Im trying to get my FPS to display in the window title but my program is just not having it.
my FPS code
void showFPS()
{
// Measure speed
double currentTime = glfwGetTime();
nbFrames++;
if ( currentTime - lastTime >= 1.0 ){ // If last cout was more than 1 sec ago
cout << 1000.0/double(nbFrames) << endl;
nbFrames = 0;
lastTime += 1.0;
}
}
and i want it too go just after the Version here
window = glfwCreateWindow(640, 480, GAME_NAME " " VERSION " ", NULL, NULL);
but i cant just call the void i i have to convert it too a char ? or what ?
void showFPS(GLFWwindow *pWindow)
{
// Measure speed
double currentTime = glfwGetTime();
double delta = currentTime - lastTime;
nbFrames++;
if ( delta >= 1.0 ){ // If last cout was more than 1 sec ago
cout << 1000.0/double(nbFrames) << endl;
double fps = double(nbFrames) / delta;
std::stringstream ss;
ss << GAME_NAME << " " << VERSION << " [" << fps << " FPS]";
glfwSetWindowTitle(pWindow, ss.str().c_str());
nbFrames = 0;
lastTime = currentTime;
}
}
Just a note, cout << 1000.0/double(nbFrames) << endl;
wouldn't give you "frame-per-second" (FPS), but would give you "milliseconds-per-frames" instead, most likely 16.666 if you are at 60 fps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With