Timer Function

Is it possible to pass a paramter to a function inside a timer, or can the timer only do, say, update() then in the update function i pass the parameter to the function?

This doesn’t sound like an OpenGL question. If it is, please post a code snippet to illustrate your problem.

Well I dont really have any code for it. I need to write a timer function to increase an angle of a variable. So i was thinking it would be something along the lines of

void timer (int value){
glutTimerFunc(40, Timer, 0);

Or something weird like

void timer (int value){
glutTimerFunc(40, Timer, 0);

I am thinking i will need to post the angle increase in the display function. Im learning it in a class that is mostly teaching openGL, so assumed it was

I think I see what you’re saying now.

I wouldn’t display your scene in the timer function. Use glutDisplayFunc() to register a function that does that.

When you want to have the display function called, call glutPostRedisplay().

As far as the timer function to update world state, you can just have the timer callback increment a global “angle” variable and return. That’s one way to do it. GLUT is really just for simple test programs, so I wouldn’t get too caught up on using a global here.

Do you mean call the glutPostRedisplay in the timer. Basically the question i am trying to solve is,

Write a timer function that will increase and angle variable by 45 degrees and pass it to setAngle function and cause the display function to be called 10 times p/s.

Here is an example that does something really similar to what you want.

One important thing to do inside the timer callback is to recall glutTimerFunc. Otherwise it will stop once the first call done.

another way is to register the “void display()” function in which you call 2 other functions:

void display()

float frametime = ...; // for time-based animations