PDA

View Full Version : Timing the redisplay?



Molotov
05-17-2004, 07:04 PM
Hi im currently using the glutIdleFunc() callback to call glutPostRedisplay() as a way of doing animation in my program. Im concerned about animation speeds on different computers (due to their varrying speeds), so I'm wondering if there is a way to set something like a redisplay every clock tick?

dorbie
05-17-2004, 11:21 PM
Use elapsed time to pace the animation. This way faster systems get a smoother product.

Molotov
05-18-2004, 10:31 AM
could you elaborate? I understand what you mean but the implementation I come up with might not be the best? are there examples anywhere I could look at?

dorbie
05-18-2004, 02:40 PM
Measure the time since the last update using system calls and use that as the basis for your animation. For example if you apply a movement to an object scale it by the elapsed time. Same with things like acceleration etc.

nexusone
05-19-2004, 08:03 AM
Use glutTimerFunc, and you can set the time interval that you display is updated.
And is not effected by CPU speed.

glutTimerFunc( Time_in_milliseconds, function_to_call, id_number);

Note it is a one shot deal must be reset every time it is called.

void Timer_func( int id )
{

//Do something

glutPostRedisplay();
glutTimerFunc( 100(ms), Timer_func, 0); // Reset timer
}


Originally posted by Molotov:
Hi im currently using the glutIdleFunc() callback to call glutPostRedisplay() as a way of doing animation in my program. Im concerned about animation speeds on different computers (due to their varrying speeds), so I'm wondering if there is a way to set something like a redisplay every clock tick?