如何在简单的 Direct2D 应用程序中计算 fps?
嘿伙计们,感谢您的观看。我已经从 MSDN 构建了简单的 D2D 应用程序,可在此处< /a>.现在,我想绘制一些图元并添加一个 fps 计数器。
我有一个 OnRender() 事件,我在其中绘制矩形等。我还调用了 RenderTextInfo(),其中调用了 RenderTarget->DrawText。在哪里添加计算每秒帧数的逻辑?
非常感谢。
Hey guys, and thanks for looking. I have built the simple D2D app from MSDN, available here. Now, I want to draw some primitives and add an fps counter.
I have an OnRender() event, where I draw the rectangles and so on. I also have a call to RenderTextInfo() where I call RenderTarget->DrawText. Where do I add the logic for counting the number of frames per second?
Thanks much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道确切的 Direct2D 内容,但这可能会有所帮助。
基本上,你有两个选择。您可以在绘制帧时更新帧速率,也可以每秒(或任何其他时间间隔)更新帧速率。
如果在画一帧的时候算的话,就可以简单的得到画一帧时的当前时间,然后减去画最后一帧的时间。这样你就可以花时间画这个框架了。其倒数(即 1/x)就是帧速率。
如果您以固定的时间间隔进行计数,则需要在每个时间间隔触发一些事件,以检查自上次事件触发以来绘制了多少帧。将其除以你的间隔(如果是一秒,当然你不需要除以),这就是你的 fps 计数。不要忘记每次绘制框架时增加一些计数器。
I don't know the exact Direct2D stuff, but this might help.
Basically, you have two choices. Either you update the framerate when you draw a frame, or each second (or any other time interval).
If you count it when you draw a frame, you can simply get the current time when you draw a frame, and subtract from it the time you drew the last frame. That gets you the time spent drawing this frame. The reciprocal of that (i.e. 1/x) is the framerate.
If you count it at a regular time interval, you need to have some event firing at every interval that checks how many frames were drawn since the last time that event fired. Divide that by your interval (if it's one second, you don't need to divide, of course) and that's your fps count. Don't forget to increment some counter every time you draw a frame.