From 24ca4df9de202ea76cd5f533206922c32f69b796 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Fri, 30 Jul 2010 15:18:09 +0000 Subject: [PATCH] * 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 --- src/libs/mesa/glut/glutInit.cpp | 19 +++++++++++++++---- src/libs/mesa/glut/glutint.h | 1 + .../kits/opengl/glut/game_mode/game_mode.c | 9 ++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/libs/mesa/glut/glutInit.cpp b/src/libs/mesa/glut/glutInit.cpp index 401081328f..d2d32cfd16 100644 --- a/src/libs/mesa/glut/glutInit.cpp +++ b/src/libs/mesa/glut/glutInit.cpp @@ -168,7 +168,7 @@ void glutInit(int *argcp, char **argv) { break; } } - + __glutInit(); /* Create BApplication first so DisplayWidth() works */ if (geometry) { int flags, x, y, width, height; @@ -225,14 +225,25 @@ void __glutInit() { bigtime_t unused; __glutInitTime(&unused); - /* set atexit() function to destroy all windows before exiting */ - if(atexit(__glutDestroyAllWindows)) + /* set atexit() function to cleanup before exiting */ + if(atexit(__glutExitCleanup)) __glutFatalError("can't set exit handler"); - + /* similarly, destroy all windows on CTRL-C */ signal(SIGINT, sigHandler); } + +void +__glutExitCleanup() +{ + if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) > 0) + // Try to restore initial screen mode... + glutLeaveGameMode(); + + __glutDestroyAllWindows(); +} + /*********************************************************** * FUNCTION: glutInitWindowPosition (2.2) * diff --git a/src/libs/mesa/glut/glutint.h b/src/libs/mesa/glut/glutint.h index e519d77acd..c618ccd328 100644 --- a/src/libs/mesa/glut/glutint.h +++ b/src/libs/mesa/glut/glutint.h @@ -790,6 +790,7 @@ extern HDC XHDC; /* private routines from glutInit.cpp */ void __glutInitTime(bigtime_t *beginning); void __glutInit(); +void __glutExitCleanup(); /* private routines from glutMenu.cpp */ class GlutMenu; // avoid including glutMenu.h diff --git a/src/tests/kits/opengl/glut/game_mode/game_mode.c b/src/tests/kits/opengl/glut/game_mode/game_mode.c index 13e6e1dd12..2e25e73b2c 100644 --- a/src/tests/kits/opengl/glut/game_mode/game_mode.c +++ b/src/tests/kits/opengl/glut/game_mode/game_mode.c @@ -157,14 +157,9 @@ init(void) void -clean_exit(void) +on_exit(void) { printf("Exit.\n"); - - if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) { - printf("glutLeaveGameMode()\n"); - glutLeaveGameMode(); - } } @@ -226,7 +221,7 @@ main(int argc, char **argv) init(); - atexit(clean_exit); + atexit(on_exit); glutMainLoop(); return 0;