GLUT - Exiting App

Started by
1 comment, last by songho 17 years, 4 months ago
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
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 ^_^;
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 callbackatexit(exitCB);...// define exit callbackvoid exitCB(){    // clean up parogram before exit, such as deallocating    // dynamic arrays    std::cout << "Hello, I'm here." << std::endl;}

This topic is closed to new replies.

Advertisement