如何在OpenGL中计算FPS?

Mir*_*nda 8 c opengl playback

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

我应该调用此函数void play(void)还是void display(void)

或者它没有任何区别?

DSh*_*ook 7

你应该把它放在显示循环中. 这里,解释游戏的一些错综复杂的文章循环,你应该阅读.