Hello!
I'm trying to draw the resulting texture after applying a shader, into a new texture.
But the problem is that after doing this:
shaderTexture.create(1280,720);
the area where he painted the resulting texture now is just white.
My code is :
// Inclusion de OpenGL
#include <SFML/OpenGL.hpp>
#include <SFML/Graphics.hpp>
#define NORMAL_OTHER "shader/otro_normal.png"
#define TEXTURE_OTHER "shader/otro_texture.png"
int main() {
sf::RenderWindow window(sf::VideoMode(1280, 720), "window!!!");
sf::Shader miShader;
miShader.loadFromFile("shader/bumpmap.frag",sf::Shader::Fragment);
sf::RenderTexture shaderTexture;
if(!shaderTexture.create(1280,720))
return -1;
glShadeModel (GL_SMOOTH);
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
GLfloat light_position[] = { 200.0, 200.0, 800.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Normal Map
sf::Texture texturaOtra;
if (!texturaOtra.loadFromFile(NORMAL_OTHER)) {
return EXIT_FAILURE;
}
// Load a sprite to display
sf::Texture otra;
if (!otra.loadFromFile(TEXTURE_OTHER)) {
return EXIT_FAILURE;
}
sf::Sprite spriteOtra(otra);
spriteOtra.setPosition(150,150);
sf::Vector2f p;
p = spriteOtra.getPosition();
sf::Vector3f p2 = sf::Vector3f(p.x,p.y,0.0);
miShader.setParameter("position",p2);
miShader.setParameter("normalTexture", texturaOtra);
miShader.setParameter("texture", sf::Shader::CurrentTexture);
// Start the game loop
bool done = false;
while (!done) {
// Process events
sf::Event Event;
while (window.pollEvent(Event)) {
// Close window : exit
if (Event.type == sf::Event::Closed) {
done = true;
}
}
// Clear screen
window.clear();
shaderTexture.clear();
shaderTexture.draw(spriteOtra,&miShader);
shaderTexture.display();
window.draw(sf::Sprite(shaderTexture.getTexture()));
window.display();
}
window.close();
return EXIT_SUCCESS;
}
My system specifications are:
OS: Windows 7 Professional 64bits
Video Card: AMD Radeon HD 6670
IDE: Visual Studio 2008 Professional.
SFML version: 2.0 (downloaded from the official site in early March).
Sorry for my terrible English....