summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 78e3221..0359622 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,6 +4,8 @@
#include <deque>
int main() {
+ const int fps = 24;
+
sf::Texture texture;
if(!texture.loadFromFile("flag.png"))
return 1;
@@ -12,8 +14,8 @@ int main() {
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);
+ window.setVerticalSyncEnabled(false);
+ window.setFramerateLimit(0);
sf::Shader shader;
if(!shader.loadFromFile("flag.glsl", sf::Shader::Type::Fragment))
@@ -64,8 +66,9 @@ int main() {
output_image.create(flag_width, flag_height, sf::Color::Transparent);
const float playtime_sec = 2.0f;
+ const float frame_time = 1000.0 / (double)fps / 1000.0;
+ double elapsed_frame_time = 0.0;
- sf::Clock timer;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
@@ -73,7 +76,7 @@ int main() {
window.close();
}
- shader.setUniform("iTime", timer.getElapsedTime().asSeconds());
+ shader.setUniform("iTime", (float)elapsed_frame_time);
window.clear(sf::Color::Transparent);
window.draw(vertex, 4, sf::PrimitiveType::Quads, &shader);
window.display();
@@ -85,7 +88,8 @@ int main() {
std::lock_guard<std::mutex> lock(images_lock);
pending_frames.push_back(output_image);
- if(timer.getElapsedTime().asSeconds() >= playtime_sec)
+ elapsed_frame_time += frame_time;
+ if(elapsed_frame_time >= playtime_sec)
break;
}