diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-05-15 01:56:06 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-05-15 01:56:06 +0200 |
commit | cd05828923f5241b1d71ad211cce5c8605de38fd (patch) | |
tree | 6b3eb544e41f4d12a88ec56e0d34e3726c941b66 /src |
lole
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..5876efc --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,65 @@ +#include <SFML/Graphics.hpp> + +int main() { + sf::Texture texture; + if(!texture.loadFromFile("flag.png")) + return 1; + + texture.setSmooth(true); + + sf::Vector2u window_size = texture.getSize(); + sf::RenderWindow window(sf::VideoMode(window_size.x, window_size.y), "SFML works!", 0); + window.setVerticalSyncEnabled(true); + window.setFramerateLimit(24); + + sf::Shader shader; + if(!shader.loadFromFile("flag.glsl", sf::Shader::Type::Fragment)) + return 1; + + shader.setUniform("texture", texture); + + sf::Vertex vertex[4]; + vertex[0] = sf::Vertex(sf::Vector2f(0.0f, 0.0f), sf::Color::White, sf::Vector2f(0.0f, 0.0f)); + vertex[1] = sf::Vertex(sf::Vector2f(window_size.x, 0.0f), sf::Color::White, sf::Vector2f(1.0f, 0.0f)); + vertex[2] = sf::Vertex(sf::Vector2f(window_size.x, window_size.y), sf::Color::White, sf::Vector2f(1.0f, 1.0f)); + vertex[3] = sf::Vertex(sf::Vector2f(0.0f, window_size.y), sf::Color::White, sf::Vector2f(0.0f, 1.0f)); + + sf::Texture texture_output; + texture_output.create(texture.getSize().x, texture.getSize().y); + + int flag_start_x = texture.getSize().x*0.2; + int flag_start_y = texture.getSize().y*0.2; + int flag_width = texture.getSize().x*0.6; + int flag_height = texture.getSize().y*0.6; + + sf::Image output_image; + output_image.create(flag_width, flag_height, sf::Color::Transparent); + std::vector<sf::Image> frames; + + sf::Clock timer; + while (window.isOpen()) { + sf::Event event; + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) + window.close(); + } + + shader.setUniform("iTime", timer.getElapsedTime().asSeconds()); + window.clear(sf::Color::Transparent); + window.draw(vertex, 4, sf::PrimitiveType::Quads, &shader); + window.display(); + + texture_output.update(window); + sf::Image image = texture_output.copyToImage(); + output_image.copy(image, 0, 0, sf::IntRect(flag_start_x, flag_start_y, flag_width, flag_height), false); + frames.push_back(std::move(output_image)); + } + + system("rm -rf frames/*; mkdir frames"); + for(size_t i = 0; i < frames.size(); ++i) { + frames[i].saveToFile("frames/" + std::to_string(i) + ".png"); + } + system("ffmpeg -i \"frames/%d.png\" -framerate 24 -filter_complex \"fps=24,split=2[palette_in][gif];[palette_in]palettegen[palette_out];[gif]fifo[gif_fifo]; [gif_fifo][palette_out]paletteuse\" -y frames/output.gif"); + + return 0; +}
\ No newline at end of file |