如何在OpenGL中计算FPS?

时间:2011-04-11 21:30:47

标签: 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;
    }
}

我应该在void play(void)还是void display(void)

中调用此功能

或者它没有任何区别?

3 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:1)

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

答案 2 :(得分:0)

includes("typescript", "rip"); // okay
includes([1, 2, 3], 2); // okay

includes("typescript", 2); // error
includes([1, 2, 3], "rip"); // error
相关问题