如何在OpenGL中计算FPS?

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; } } 

我应该在void play(void)void display(void)调用此函数吗?

或者它没有任何区别?

你应该把它放在显示循环中。 这篇文章解释了你应该阅读的游戏循环的一些复杂性。

如果您有任何类型的同步例程,我建议您在此之后进行调用,即在大计算之前。 否则,时序计算可能不稳定并且每个循环给出不同的值……并且注意,为了使其最大化,最好具有稳定的FPS而不是波动的FPS。 即使如此微妙的波动也使得观众/玩家意识到这一切都是游戏而且沉浸感已经消失。