I was going over some example source code when I came across the glutIdleFunc which was set up as follows:

glutIdleFunc((void (*)(void))0);

What does this do?

I’ve used auxIdleFunc… I assume that these do the same thing… Pretty much whenever the display loop isn’t rendering this is the part that gets called…

Its usefull placing things in here such as animations(rotations, translations, ect.) because this will be called and then the scene will be rendered, displaying the changes… for an example of this look…

The animation with aux is at the bottom of the page and code on the next… your glut code should look really similar(basically changing all of the aux’s to glut’s except in a few simple cases).

Edit: oh yeah, just in case you don’t know… the functions name goes into the ()'s after the name… just like how you specify the display function.

[This message has been edited by Mitchell Hayenga (edited 10-15-2000).]

Actually, I was wondering about what was going on inside the brackets of this example:

glutIdleFunc((void (*)(void))0);

I assume it has the opposite effect of setting the callback function?

glutIdleFunc((void (*)(void)));

The stuff inside is just a mechanism in C for declaring a function pointer. In this case, you need to pass the name of a function that takes no arguments and returns none.


glutIdleFunc((void (*)(void))0);

Hmm, I don’t think this is a prototype, but rather something you put in your code, like any other call to GLUT to setup a callback function.
Is this correct, that you found this among other calls to GLUT in a compilable program?

First void says it’s a return type of void, i.e return nothing.

Second part is just a type conversion of the interer value zero to a void pointer. In other words, a NULL pointer. This would be the same as glutIdleFunc(NULL);

like cire said…

I’ve used this function quite a bit and I’ve never really asked the question, “What specifically happens in here?” But my understanding of it is this; When you call the glutIdleFunc(somefunction);, what happens is it will continuously call the function specified while the processor is not doing anything else. ie.instead of waiting for a command input/keyboard key press/mouse button press or movement, this function call tells the processor to keep on calling the specified function over and over again. I like to think of it as a continuous loop. Now I’m no expert in this area as I too am new to OpenGL so you may wish to read a few of the others’ responses before mine because I could be entirely in left field! If I am wrong/confused/mislead/misleading then please forgive me!

Ok, I get it. It just sets the callback function glutIdleFunc to NULL.


Don’t want to be rude here, but I think you guys forgot the zero in the code Andy first posted. The thing inside the main paratheses is a typeconverted zero. From an integer to a void pointer with value zero and no return value and no arguments. Like Andy said, it sets the GLUT idle callback to NULL.