【问题标题】:How to calculate FPS in OpenGL?如何在OpenGL中计算FPS?
【发布时间】:2011-04-11 21:30:47
【问题描述】:
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) 中调用这个函数吗?

还是没有区别?

【问题讨论】:

标签: c opengl playback


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    如果您有任何类型的同步例程,我建议您在此之后调用,即在大计算之前。否则,计时计算可能会不稳定,并在每个循环中给出不同的值......请注意,最好有一个稳定的 FPS,而不是仅仅为了最大化它而使用一个波动的 FPS。甚至如此细微的波动也让观众/玩家意识到这一切都是一场游戏,沉浸感消失了。

    【讨论】:

      【解决方案3】:
      void CalculateFrameRate()
      {
          static float framesPerSecond = 0.0f;
          static int fps;
          static float lastTime = 0.0f;
          float currentTime = GetTickCount() * 0.001f;
          ++framesPerSecond;
          glPrint("Current Frames Per Second: %d\n\n", fps);
          if (currentTime - lastTime > 1.0f)
          {
              lastTime = currentTime;
              fps = (int)framesPerSecond;
              framesPerSecond = 0;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多