Sign in to follow this  
Luis_Ga

GLUT - Exiting App

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this