#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
int main(int argc, char* argv[])
{
sf::RenderWindow window(sf::VideoMode(550, 350), "SFML window");
sf::RenderTexture target;
target.create(window.getSize().x, window.getSize().y);
sf::Shader shader;
if(!shader.loadFromMemory(
"uniform sampler2D inputTex;\
void main()\
{\
vec4 renderTargetColor = texture2D(inputTex, gl_TexCoord[0].xy);\
gl_FragColor = vec4(0, renderTargetColor.g, renderTargetColor.r, 1);\
}", sf::Shader::Fragment))
return 1;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
}
}
sf::RectangleShape a(sf::Vector2f(250, 250));
a.setFillColor(sf::Color(0, 255, 0, 255));
target.clear(sf::Color(255, 0, 0, 255));
target.draw(a);
target.display();
shader.setParameter("inputTex", target.getTexture());
sf::Sprite b(target.getTexture());
window.clear();
window.draw(b, &shader);
window.display();
sf::sleep(sf::seconds(5.f));
}
return 0;
}