2011-04-11 126 views
6
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)中調用此函數?如何計算OpenGL中的FPS?

或者它沒有任何區別?

+0

什麼是'play(void)'?請注意,由於GPU是不可預知的,因此情況會更復雜一點:http://stackoverflow.com/questions/8779936/correct-way-to-calculate-the-fps – 2016-03-17 08:16:49

回答

4

你應該把它放在顯示循環中。 Here's這篇文章解釋了一些你應該閱讀的遊戲循環的複雜性。

1

如果您有任何類型的同步程序,我建議您在此之後發出呼叫,即在大計算之前。否則,計時計算可能是抖動,並給每個循環不同的值...和一個音符,最好有一個穩定的FPS比波動的FPS只是爲了最大化它。這種波動如此微妙,使得觀衆/玩家意識到這只是一場遊戲,而沉浸式遊戲卻不見了。