How to calculate FPS in OpenGL?

后端 未结 3 685
暗喜
暗喜 2021-02-15 13:06
void CalculateFrameRate()
{    
    static float framesPerSecond    = 0.0f;       // This will store our fps
    static float lastTime   = 0.0f;       // This will hold          


        
相关标签:
3条回答
  • 2021-02-15 13:23
    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;
        }
    }
    
    0 讨论(0)
  • 2021-02-15 13:24

    You should put it in the display loop. Here's an article that explains some intricacies of game loops that you should read.

    0 讨论(0)
  • 2021-02-15 13:45

    If you have any kind of synchronization routine I suggest you place the call just after that, ie prior the big calculations. Otherwise the timing calculations can be shaky and give different values each loop...and a note, it's better to have a steady FPS than a fluctuating FPS just to maximize it. The fluctuation even so subtle makes the viewer/player aware that it's all a game and the immersion is lost.

    0 讨论(0)
提交回复
热议问题