I don’t understand how to use the glutTimerFunc().
I have the glutTimerFunc(ms, myTimerFunc, 0) in my main function.
I’m trying it out in a simple program where a line is drawn. then another object, say an “X” is drawn at a later time interval.
I have my display function to draw these objects.
But what do I put in the “myTimerFunc” function?
In the timer callback you update any variables you need to get the animation to change, then you call the update function, I don’t remember what it is called in glut, but it’s redisplay, invalidate, update or something like that, check the docs, when you call this function you tell the OS that you want to redraw the OpenGL contents and when you exit the timer callback the OS will notice this and call the display function to redraw the OpenGL contents.
thanks for responding…
but that would be what I would do if I wanted the whole picture to translate to another location or something, right?
but what if i have 2 functions, one to draw object A and one to draw object B. and i draw object A, then after a certain time interval, i want object B to be drawn, how do I do that? can you have 2 display functions, one for object A and one for object B? I mean in my main function, I have glutDisplayFunc(myDisplay); then in myDisplay I call the function to draw object A, then do I just call the function to draw object B from the myTimerFunc() ?
And I don’t know what you mean by the redisplay or whatever it is that you can’t remember the name of.
Where can I find documentation on this?
The function is glutPostRedisplay(), this will force the OS to repaint the OpenGL contents as soon as possible.
What you would do would be to have a variable x initialized to 0 at startup, when your timer callback is called you set x=1 and call glutPostRedisplay().
In your display callback you have the code:
if( x == 0)
draw_object_A();
else
draw_object_B();
some event set’s the glutTimerFunc.
then this is called
void timer( int id)
{
Object_A = TRUE; // Turn on our object
}
Note this is just a simple, example.
Originally posted by zaxxy:
[b]thanks for responding…
but that would be what I would do if I wanted the whole picture to translate to another location or something, right?
but what if i have 2 functions, one to draw object A and one to draw object B. and i draw object A, then after a certain time interval, i want object B to be drawn, how do I do that? can you have 2 display functions, one for object A and one for object B? I mean in my main function, I have glutDisplayFunc(myDisplay); then in myDisplay I call the function to draw object A, then do I just call the function to draw object B from the myTimerFunc() ?
And I don’t know what you mean by the redisplay or whatever it is that you can’t remember the name of.
Where can I find documentation on this?