How to calculate FPS in OpenGL?

后端 未结 3 683
暗喜
暗喜 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;
        }
    }
    

提交回复
热议问题