* Group all GLUT exit cleanup tasks in one place, __glutExitCleanup().

* Automatically leave game mode if it's still active at exit
 * Remove explicit game mode cleanup from testbed app.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37822 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2010-07-30 15:18:09 +00:00
parent 6e55a1104a
commit 24ca4df9de
3 changed files with 18 additions and 11 deletions
+15 -4
View File
@@ -168,7 +168,7 @@ void glutInit(int *argcp, char **argv) {
break; break;
} }
} }
__glutInit(); /* Create BApplication first so DisplayWidth() works */ __glutInit(); /* Create BApplication first so DisplayWidth() works */
if (geometry) { if (geometry) {
int flags, x, y, width, height; int flags, x, y, width, height;
@@ -225,14 +225,25 @@ void __glutInit() {
bigtime_t unused; bigtime_t unused;
__glutInitTime(&unused); __glutInitTime(&unused);
/* set atexit() function to destroy all windows before exiting */ /* set atexit() function to cleanup before exiting */
if(atexit(__glutDestroyAllWindows)) if(atexit(__glutExitCleanup))
__glutFatalError("can't set exit handler"); __glutFatalError("can't set exit handler");
/* similarly, destroy all windows on CTRL-C */ /* similarly, destroy all windows on CTRL-C */
signal(SIGINT, sigHandler); signal(SIGINT, sigHandler);
} }
void
__glutExitCleanup()
{
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) > 0)
// Try to restore initial screen mode...
glutLeaveGameMode();
__glutDestroyAllWindows();
}
/*********************************************************** /***********************************************************
* FUNCTION: glutInitWindowPosition (2.2) * FUNCTION: glutInitWindowPosition (2.2)
* *
+1
View File
@@ -790,6 +790,7 @@ extern HDC XHDC;
/* private routines from glutInit.cpp */ /* private routines from glutInit.cpp */
void __glutInitTime(bigtime_t *beginning); void __glutInitTime(bigtime_t *beginning);
void __glutInit(); void __glutInit();
void __glutExitCleanup();
/* private routines from glutMenu.cpp */ /* private routines from glutMenu.cpp */
class GlutMenu; // avoid including glutMenu.h class GlutMenu; // avoid including glutMenu.h
@@ -157,14 +157,9 @@ init(void)
void void
clean_exit(void) on_exit(void)
{ {
printf("Exit.\n"); printf("Exit.\n");
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) {
printf("glutLeaveGameMode()\n");
glutLeaveGameMode();
}
} }
@@ -226,7 +221,7 @@ main(int argc, char **argv)
init(); init();
atexit(clean_exit); atexit(on_exit);
glutMainLoop(); glutMainLoop();
return 0; return 0;