Tengo una variable int llamada FrameCount la cual, muestra un valor incorrecto al menos que haga std::cout<<FrameCount<<std::endl antes del if ((currentTime - t0Value) > theTimeInterval).
Código:
Código:
void Engine::calcFPS(double theTimeInterval) { static double fps = 0.0; // Set the initial FPS value to 0.0 // Get the current time in seconds since the program started (non-static, so executed every time) double currentTime = glfwGetTime(); // Ensure the time interval between FPS checks is sane (low cap = 0.1s, high-cap = 10.0s) // Negative numbers are invalid, 10 fps checks per second at most, 1 every 10 secs at least. if (theTimeInterval < 0.1) { theTimeInterval = 0.1; } if (theTimeInterval > 10.0) { theTimeInterval = 10.0; } std::cout<<FrameCount<<std::endl; // Si no hago esto, la variable toma valores incorrectos // Calculate and display the FPS every specified time interval if ((currentTime - t0Value) > theTimeInterval) { // Calculate the FPS as the number of frames divided by the interval in seconds fps = FrameCount/(currentTime - t0Value); // Convert the fps value into a string using an output stringstream std::ostringstream stream; stream << fps; std::string fpsString = stream.str(); // Append the FPS value to the window title details theWindowTitle = " | FPS: " + fpsString; // Convert the new window title to a c_str and set it const char* pszConstString = theWindowTitle.c_str(); glfwSetWindowTitle(pszConstString); // Reset the FPS frame counter and set the initial time to be now FrameCount = 0; t0Value = glfwGetTime(); } else // FPS calculation time interval hasn't elapsed yet? Simply increment the FPS frame counter { FrameCount++; } }