tags:

views:

135

answers:

4

so how? my app is running at 60FPS, but i want 30.

+3  A: 

one word: sleep

Lie Ryan
What library or OS's sleep() are you talking about? Many don't have the resolution necessary to achieve smooth framerates.
LarsH
+4  A: 

Assuming you have a target frame rate, you could measure how long its been since the last time you finished rendering. From there, you could sleep for targetMsPerFrame - timeElapsed.

ItzWarty
+1 agreed. If your target framerate is 30fps, your targetMsPerFrame is (1000 / 30) milliseconds.
LarsH
+3  A: 

Take a look at WGL_EXT_swap_control or GLX_EXT_swap_control extensions, regarding to your operating system. This is used to control the VSync, but should be usefull to render at half your monitor refresh rate.

tibur
A: 

@itzWarty has a correct answer on how to set your framerate. It's called "clamping" or "locking" the framerate.

But why do you want to do that? If you're trying to avoid hogging resources, clamping the framerate is good.

Otherwise you might want to let framerate go as fast as possible, in order to make people with great honking graphics cards feel like they didn't waste their money. In that case you need to make your animation time-based rather than frame-based. I.e. scale your animation steps according to how much time has passed since the previous step. E.g.

x += dx * (timeNow - timePrev) / typicalDuration; // pseudoCode
LarsH