Alright I tested it now and I get something I really don't understand at all.
Thats how I understood: I should print my stuff on texture1 and then I pass this texture to the shader.
After this I draw my shape on texture2 with the shader. So I don't use the same texture for reading and drawing.
However if I draw the shape it has the color I cleared texture1 with (green) and not magenta (which I set in the shader if the pixel is black)
Thats the code:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Test", sf::Style::Close);
window.setFramerateLimit(60);
sf::Event windowEvent;
sf::RenderTexture texture, temp;
sf::Shader shader;
sf::RectangleShape test(sf::Vector2f(50, 50));
test.setFillColor(sf::Color::Black);
test.setPosition(400, 300);
if(!texture.create(800, 600)) window.close();
if(!temp.create(800, 600)) window.close();
if(!shader.loadFromFile("test.frag", sf::Shader::Fragment)) window.close();
while(window.isOpen())
{
while(window.pollEvent(windowEvent))
{
if(windowEvent.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Blue);
texture.clear(sf::Color::Green);
temp.clear(sf::Color::Black);
texture.draw(test);
//texture.display();
shader.setParameter("texture", texture.getTexture());
temp.draw(test, &shader);
window.draw(sf::Sprite(temp.getTexture()));
window.display();
}
return EXIT_SUCCESS;
}
shader:
uniform sampler2D texture;
void main()
{
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
if(pixel == vec4(0.0, 0.0, 0.0, 1.0))
pixel = vec4(1.0, 0.0, 1.0, 1.0);
gl_FragColor = pixel;
}