• Advertisement
Sign in to follow this  

What is the use of the value parameter in glutTimerFunc?

This topic is 3029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The first argument is the "to be slept" time and the second is the pointer to the callback function. But why do I have to provide another integer to this callback function, which is the third argument in glutTimerFunc?

Share this post


Link to post
Share on other sites
Advertisement
So that you can associate context with callback. The int will be passed to callback function.

Third parameter can be anything - only you know what it means. Example:
void callback(int value) {
switch (int) {
case 1 : printf("Hello");
case 2 : printf("World");
}
};

...

glutTimerFunc(100, callback, 1);
glutTimerFunc(200, callback, 2);
Here, same function is used, different parameter will be passed.

This is common idiom for asynchronous invocation, where the caller will be long gone when the callback is invoked.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
So that you can associate context with callback. The int will be passed to callback function.

Third parameter can be anything - only you know what it means. Example:
void callback(int value) {
switch (int) {
case 1 : printf("Hello");
case 2 : printf("World");
}
};

...

glutTimerFunc(100, callback, 1);
glutTimerFunc(200, callback, 2);
Here, same function is used, different parameter will be passed.

This is common idiom for asynchronous invocation, where the caller will be long gone when the callback is invoked.




OK thanks a lot.
I was a little confused as I thought this parameter is part of the timing.
You made it clear that it is only used to pass any information to the callback.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement