function in main

hi, i wonder in my main function
what is the difference between
glutDisplayFunc(Draw)
and Draw

do i really need glutDisplayFunc to call Draw method to draw the object in main?
what i need that ?

is the glutMainLoop() means keep looping the main function ?

glutDisplayFunc() is used to tell GLUT what function to call to draw. Draw() and glutDisplayFunc() are two completely different things. You only need to call glutDisplayFunc() once at the beginning of your code to specify which function handles drawing.

glutMainLoop() activates the internal GLUT animation loop. Until you call this, the function specified by glutDisplayFunc() and glutIdleFunc() won’t be called automatically by GLUT.

Also, glutMainLoop() only needs to be called once, after you setup all the other GLUT stuff (ie, glutDisplayFunc, etc.)

Originally posted by banzai889:
[b]hi, i wonder in my main function
what is the difference between
glutDisplayFunc(Draw)
and Draw

do i really need glutDisplayFunc to call Draw method to draw the object in main?
what i need that ?

is the glutMainLoop() means keep looping the main function ?[/b]

Glut knows nothing about your program. You must tell it which functions in your program do what. You do this via a callback mechanism. When you write glutDisplayFunc(draw) you are telling glut to “callback” your draw() function every time glut thinks it need the scene to be rendered. Another example; when you write glutKeyboardFunc(keyboard) you are telling glut that keyboard() is the function to call when a key has been pressed.

The function glutMainLoop() does not call main(). Again, glut does not know anything about your program. There is, however, looping occuring inside of glutMainLoop(). Here is some VERY simplified psuedo code for glutMainLoop():

glutMainLoop()
{
loop
{
check for an event.
if no events
call user idle function
else
based on event determine if a user
function should be called and call it
}
}

Hope this helps.