From 82d1cb97a1f788f00fbdc6f76b0ce6831b95bd44 Mon Sep 17 00:00:00 2001 From: Caesar2011 Date: Fri, 23 Sep 2016 14:19:11 +0200 Subject: [PATCH] Loop counter depending on time --- opengl-test-two/main.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/opengl-test-two/main.cpp b/opengl-test-two/main.cpp index 2d8746c..e882b24 100644 --- a/opengl-test-two/main.cpp +++ b/opengl-test-two/main.cpp @@ -153,16 +153,13 @@ int main(int argc, char* args[]) { int loopNumber = -1; double lastTime = glfwGetTime(); + double lastTimeLoop = glfwGetTime(); int nbFrames = 0; /* Loop until the user closes the window */ while (!glfwWindowShouldClose(window)) { - // Foreground texture counter - loopNumber++; - if (loopNumber >= lenTexFG) { - loopNumber = 0; - } + // Measure speed double currentTime = glfwGetTime(); @@ -175,6 +172,15 @@ int main(int argc, char* args[]) { lastTime += 1.0; } + // Foreground texture counter + if ( currentTime - lastTimeLoop >= 0.08 ){ + loopNumber++; + if (loopNumber >= lenTexFG) { + loopNumber = 0; + } + lastTimeLoop += 0.08; + } + // Set current foreground texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texFGs[loopNumber]);