Closing a GLUT App

Hi there

Simple thing: I want to exit my GLUT app, how to do that?

I don´t want to use the “exit ()” function, because it stops my whole app, but i only want to stop GLUTs Mainloop.

Is there a clean way to do that? I couldn´t find anything in GLUTs doc. Simply destroying the window when ESC was pressed, yields to a crash.


You can’t exit the main loop in GLUT. If this is not what you want, then you have to use another windowing library. I think GLFW is pretty good.


I think there is no other possibility than to call exit because the documentation says that glutMainLoop() never returns.
I suppose that it has a while(1) loop which can’t be left.


Hm, that´s a bit strange, isn´t it? Did they simply forget to include that into GLUT?

Problem is, i cannot change to anything else, i have to use GLUT.

Well, under Windows, i am pretty sure i can exit the main-loop, by sending a WM_CLOSE message. Any idea, how to do that under Linux?


If you take a look at the GLUT source, you can see that there is no way out of the loop entered in glutMainLoop. If you manage to send something that close the window, you’re not going to get out of glutMainLoop.

I doubt this is a mistake, since GLUT have been around for quite some time, even before the development of it stopped a few years ago, and is used quite alot. I would guess that there was no real reason for it, since you’re not supposed to use GLUT for anything but smaller demos and similar stuff anyways.

What is it exactly you want to do after exiting the main loop? Are you really sure it’s something that can’t be done right before calling exit() to exit the program or something?

Well, i wouldn´t use GLUT if i wasn´t forced to use it. That´s why i do use it.

Actually, i wanted to do some clean up after the main-loop. But well, if it´s not possible to exit the main-loop, i will have to do the clean up somewhere else.

I still think it is a poor decision, not to include something to properly exit that loop. exit() looks pretty much like a brute-force thing, i thought there might be a more elegant way.

Thanks anyway,

what’s wrong with atexit() ?