Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opengl glutmainloop()

Tags:

opengl

glut

i just started off using OpenGL and it seems it is not easy to understand the working of the glutMainLoop() what really happens there? Does it stay there doing nothing till any of the function calls responds?

like image 875
codemax Avatar asked Dec 07 '09 19:12

codemax


People also ask

What is glutMainLoop in opengl?

glutMainLoop tells the program to enter the GLUT event processing loop. (This just means the program sits and waits for things to happen, such as window refreshes, window resizes, mouse clicks, key presses, etc.) glutMainLoop never exits, so it should always be the last line of the main program.

What is the purpose of glutMainLoop () function in opengl?

Well glutMainLoop is the main function the keeps calling and calling the displaying functions and which also keeps your window actually opened.

How do I leave glutMainLoop?

you can exit the glut main loop via, glutLeaveMainLoop . Of course, this requires you to use freeglut or openglut. The original version of glut does not conatin this functionality… otherwise, you can call exit() to kill the app, and register an atexit function to get notification of when the exit func is called.


2 Answers

It calls your display callback over and over, calling idle between so that it can maintain a specific framerate if possible, and others if necessary (such as if you resize the window or trigger an input event).

Essentially, within this function is the main program loop, where GLUT does most of the work for you and allows you to simply set up the specific program logic in these callbacks. It's been a while since I've worked with GLUT, and it is certainly confusing at first.

In your display callback should obviously be your main logic to draw whatever it is that should be going on. In the idle callback should be some very lightweight operations to determine what the change in state should be from the last time display was called to the next time. For example, if you're animating something, this would be where you change its position or orientation.

like image 178
StrixVaria Avatar answered Dec 12 '22 07:12

StrixVaria


It is exactly as StrixVaria has stated.

glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.

Taken from here

like image 42
Anthony Forloney Avatar answered Dec 12 '22 06:12

Anthony Forloney