• Advertisement
Sign in to follow this  

GLUT - Exiting App

This topic is 4087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When using GLUT there doesn't seem to be a way to programmatically tell GLUT to exit the main loop. Does anyone know if there is a way to tell GLUT through code that we want it to exit? This way it would be possible to exit the app through code rather than clicking on the X button on the window title bar. -Luis

Share this post


Link to post
Share on other sites
Advertisement
you can do this (withing the main loop function):
if(event){
SaveAllState();//optional
DoAnyEndingShow();//optional
exit(0);
}
not sure if there is another way (by using glut functions).
take care ^_^;

Share this post


Link to post
Share on other sites
You may try to register a callback fuction with atexit(). When you press X button, GLUT directly calls exit() instead of returning your program. Therefore, you don't have a chance to clean up your program. By adding "exit" callback, and when exit() is called, it will direct to your callback function.

Implementation is same as registering GLUT callback functions:
// declare function prototype
#include <cstdlib>
void exitCB();
...

// register callback
atexit(exitCB);
...

// define exit callback
void exitCB()
{
// clean up parogram before exit, such as deallocating
// dynamic arrays
std::cout << "Hello, I'm here." << std::endl;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement