我正尝试在我的立方体渲染程序中显示每秒的帧数。我想看看它的表演。那么,我该怎么做呢?我已经对此进行了研究,但我看到的示例要么使用了多个类但仍然不起作用,要么使用了我没有的库。有没有办法通过使用像ctime这样的预装库来获得FPS?我正在用C++使用OpenGL。
下面是我的(空)函数:
void GetFPS()
{
}
然后我在渲染函数中使用以下命令显示我的FPS:
std::cout << xRot << " " << yRot << " " << zRot << " " << FPS << "n"; //xRot, yRot, and zRot are my cube's rotation.
我的程序设置为60fps,但我希望看到实际的fps,而不是它设置的值。
3条答案
按热度按时间x33g5p2x1#
您必须使用
clock()
对两个不同的时间间隔进行采样,但请注意其中存在几个问题:clock()
你会得到很多次0,有时你会测量到实时(在我的情况下,它只有15/16毫秒的跳跃)做到这一点:
当您执行一些需要几秒钟的操作时,上面的代码也可以工作。我做了一个每秒更新的计算,你也可以更频繁地更新它。(请注意,我在我的大多数需要FPS的项目中都使用了相同的代码)
dgsult0t2#
只需节省渲染场景前后的时间,然后进行简单的计算。
下面是一个使用
<ctime>
的clock()
函数的示例。(请注意,clock()
在不同平台上的工作方式不同)8xiog9wr3#
只要在任何循环中调用它,就可以测量每秒的调用次数。