glutTimerFunc() ------- NEED HELP PLEASE

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?

thanks,
very confused

Hi !

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.

I hope you get the idea…

Mikael

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?

please help…anybody…

thanks

Hi again !

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();

Something like that.
Mikael

how does glutPostRedisplay() work?
is it glutPostRedisplay(drawObjectB)?

This is a update screen call in glut, any time you change the position of an object the whole scene must be redrawn (that is every object).

Go to my website and look at some of the glut examples to get a better understanding of how glut works.

http://www.angelfire.com/linux/nexusone/

Originally posted by zaxxy:
[b]how does glutPostRedisplay() work?
is it glutPostRedisplay(drawObjectB)?

[/b]

You use a variable and the timer function.

void display(void)
{

if (Object_A ) draw_object( A );

if (Object_B ) 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?

please help…anybody…

thanks

[/b]