在openGL中设置每秒最大帧数 [英] setting max frames per second in openGL

查看:1820
本文介绍了在openGL中设置每秒最大帧数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法计算应该进行多少更新以达到所需的帧速率,而不是系统特定?我发现对于windows,但我想知道如果这样的东西存在于openGL本身。它应该是某种定时器。



或者我还能如何防止FPS大幅下降?这次我测试它在绘制大量的顶点在线,并使用fraps我可以看到帧速率从400到200 fps,明显减慢绘制它。

假设您有一个名为 maximum_fps 的变量,其中包含要显示的最大帧数。



然后你测量最后一帧所花费的时间(定时器会做)。



你说你想在你的应用程序上最多60FPS。然后您希望测量的时间不低于1/60。如果测量的时间较短,那么您调用 sleep()可以达到帧的剩余时间。


  • 或者你可以有一个变量 tick ,它包含应用程序的当前游戏时间。使用相同的定时器,您将在应用程序的每个主循环中递增它。然后,在你的绘图例程中,根据 tick var计算位置,因为它包含应用程序的当前时间。



    选项 2 的最大优点是,您的应用程序将更容易调试,因为您可以使用 tick 变量,前进和后退的时间,只要你想要。这是一个加。



  • Is there any way to calculate how much updates should be made to reach desired frame rate, NOT system specific? I found that for windows, but I would like to know if something like this exists in openGL itself. It should be some sort of timer.

    Or how else can I prevent FPS to drop or raise dramatically? For this time I'm testing it on drawing big number of vertices in line, and using fraps I can see frame rate to go from 400 to 200 fps with evident slowing down of drawing it.

    解决方案

    You have two different ways to solve this problem:

    1. Suppose that you have a variable called maximum_fps, which contains for the maximum number of frames you want to display.

      Then You measure the amount of time spent on the last frame (a timer will do)

      Now suppose that you said that you wanted a maximum of 60FPS on your application. Then you want that the time measured be no lower than 1/60. If the time measured s lower, then you call sleep() to reach the amount of time left for a frame.

    2. Or you can have a variable called tick, that contains the current "game time" of the application. With the same timer, you will incremented it at each main loop of your application. Then, on your drawing routines you calculate the positions based on the tick var, since it contains the current time of the application.

      The big advantage of option 2 is that your application will be much easier to debug, since you can play around with the tick variable, go forward and back in time whenever you want. This is a big plus.

    这篇关于在openGL中设置每秒最大帧数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆