Jump to content
  • Advertisement
Sign in to follow this  
Luis_Ga

GLUT - Exiting App

This topic is 4239 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!