1
Graphics / Re: Shader problem
« on: August 15, 2018, 02:35:42 pm »
I've added another rendertexture inside loop and it works perfectly. Thank you much.
Here's code after changes:
Here's code after changes:
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
int main() {
sf::Sprite sprite;
sf::Texture texture;
if (!texture.loadFromFile("background.jpg")) {}
sprite.setTexture(texture);
sf::Shader blurShader;
if (!blurShader.loadFromFile("blur.frag", sf::Shader::Fragment)) {}
blurShader.setUniform("texture", sf::Shader::CurrentTexture);
blurShader.setUniform("blur_radius", 0.001f);
sf::RenderTexture rendertexture;
rendertexture.create(1280, 720);
rendertexture.clear();
sf::RenderTexture rendertexture2;
rendertexture2.create(1280, 720);
rendertexture2.clear();
for (int i = 50; i >= 0; i--) {
rendertexture.draw(sprite, &blurShader);
rendertexture.display();
sprite.setTexture(rendertexture.getTexture());
rendertexture2.draw(sprite, &blurShader);
rendertexture2.display();
sprite.setTexture(rendertexture2.getTexture());
}
sprite.setPosition(0, 0);
sf::RenderWindow window(sf::VideoMode(1280, 720), "Peppa pig");
sf::Event event;
while (window.isOpen()) {
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
exit(0);
else if (event.key.code == sf::Keyboard::Escape)
exit(0);
}
window.clear();
window.draw(sprite);
window.display();
}
}
#include <SFML/Graphics.hpp>
int main() {
sf::Sprite sprite;
sf::Texture texture;
if (!texture.loadFromFile("background.jpg")) {}
sprite.setTexture(texture);
sf::Shader blurShader;
if (!blurShader.loadFromFile("blur.frag", sf::Shader::Fragment)) {}
blurShader.setUniform("texture", sf::Shader::CurrentTexture);
blurShader.setUniform("blur_radius", 0.001f);
sf::RenderTexture rendertexture;
rendertexture.create(1280, 720);
rendertexture.clear();
sf::RenderTexture rendertexture2;
rendertexture2.create(1280, 720);
rendertexture2.clear();
for (int i = 50; i >= 0; i--) {
rendertexture.draw(sprite, &blurShader);
rendertexture.display();
sprite.setTexture(rendertexture.getTexture());
rendertexture2.draw(sprite, &blurShader);
rendertexture2.display();
sprite.setTexture(rendertexture2.getTexture());
}
sprite.setPosition(0, 0);
sf::RenderWindow window(sf::VideoMode(1280, 720), "Peppa pig");
sf::Event event;
while (window.isOpen()) {
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
exit(0);
else if (event.key.code == sf::Keyboard::Escape)
exit(0);
}
window.clear();
window.draw(sprite);
window.display();
}
}