Advertisement

glutTimerFunc question

Started by October 15, 2013 04:05 PM
3 comments, last by pressgreen 11 years, 4 months ago

Does the glutTimerFunction work on a thread separate from the main thread when it is executed? Used to call the function that encapsulates it, when it calls that parent function it does not immediately get placed in a stack. I mean the line proceeding glutTimerFunc is then executed before the next call to the parent function is executed. I thought in a recursive function the line proceeding the call to the function is not executed until the base case is satisfied. Why is this or how is this working in the background? What is the voodoo behind the glutTimerFunction?

J-GREEN

Greenpanoply

There's nothing spectacular about it. It starts a timer, and when the timer expires, GLUT event loop issues a call to the timer callback. No additional threads are needed or used. It probably uses OS-specific timer events, and when the OS notifies GLUT that the timer has expired, GLUT responds by calling your callback.

Advertisement

When you say "GLUT even loop issues a call to the timer callback", do you mean the GLUT event loop calls the parent function that encapsulates the glutTimerFunction?

J-GREEN

Greenpanoply

It's not very clear what you mean by parent function. When you call glutTimerFunc() you pass it a function pointer. When the GLUT main loop notices the requested amount of time has passed it calls that function pointer.

Brother Bobs edit makes more sense to me now. My callback function that I place the glutTimerFunc is what I was thinking when I was saying parent function. Thanks that makes a lot of sense.

J-GREEN

Greenpanoply

This topic is closed to new replies.

Advertisement