How to calculate FPS in OpenGL?

void CalculateFrameRate() { static float framesPerSecond = 0.0f; // This will store our fps static float lastTime = 0.0f; // This will hold the time from the last frame float currentTime = GetTickCount() * 0.001f; ++framesPerSecond; if( currentTime - lastTime > 1.0f ) { lastTime = currentTime; if(SHOW_FPS == 1) fprintf(stderr, "\nCurrent Frames Per Second: %d\n\n", (int)framesPerSecond); framesPerSecond = 0; } } 

Should I call this function in void play(void) or void display(void) ?

Or does it make no difference?

+6
source share
2 answers

If you have any kind of synchronization procedure, I suggest you put the call right after that, that is, before big calculations. Otherwise, time calculations can be shaky and give different values ​​for each loop ... and note: it is better to have a stable FPS than a fluctuating FPS in order to maximize it. The fluctuation, even so subtle, makes the viewer / player realize that all game and immersion are lost.

+1
source

Source: https://habr.com/ru/post/885682/


All Articles