From 364e1ba69200b10cb2b7108cbaeafe98ac630281 Mon Sep 17 00:00:00 2001 From: "John F. Fay" Date: Thu, 17 Mar 2011 02:53:40 +0000 Subject: [PATCH] Fixing the unspecified game mode parameter problem per e-mail from Diederick Niehorster dated 3/16/11 1:06 AM -- putting in both 'gamemode-unspecified' patch files at once git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@901 7f0cb862-5218-0410-a997-914c9d46530a --- src/freeglut_gamemode.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index 137f1ea..7569d1f 100644 --- a/src/freeglut_gamemode.c +++ b/src/freeglut_gamemode.c @@ -364,7 +364,7 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) # ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H /* - * This is also used by applcations which check modes by calling + * This is also used by applications which check modes by calling * glutGameModeGet(GLUT_GAME_MODE_POSSIBLE), so allow the check: */ if( haveToTest || fgDisplay.DisplayModeValid ) @@ -372,6 +372,33 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) XF86VidModeModeInfo** displayModes; int i, displayModesCount; + /* current display mode was queried in fghRememberState + * set defaulted values to the current display mode's + */ + if (fgState.GameModeSize.X == -1) + { + fgState.GameModeSize.X = fgDisplay.DisplayMode.hdisplay; + } + if (fgState.GameModeSize.Y == -1) + { + fgState.GameModeSize.Y = fgDisplay.DisplayMode.vdisplay; + } + if (fgState.GameModeDepth == -1) + { + /* can't get color depth from this, nor can we change it, do nothing + * TODO: get with XGetVisualInfo()? but then how to set? + */ + } + if (fgState.GameModeRefresh != -1) + { + /* Compute the displays refresh rate, dotclock comes in kHz. */ + int refresh = ( fgDisplay.DisplayModeClock * 1000 ) / + ( fgDisplay.DisplayMode.htotal * fgDisplay.DisplayMode.vtotal ); + + fgState.GameModeRefresh = refresh; + } + + /* query all possible display modes */ if( !XF86VidModeGetAllModeLines( fgDisplay.Display, fgDisplay.Screen, @@ -516,11 +543,14 @@ void FGAPIENTRY glutGameModeString( const char* string ) string ); - /* Hopefully it worked, and if not, we still have the default values */ - if ( width > 0 ) fgState.GameModeSize.X = width; - if ( height > 0 ) fgState.GameModeSize.Y = height; - if ( depth > 0 ) fgState.GameModeDepth = depth; - if ( refresh > 0 ) fgState.GameModeRefresh = refresh; + /* All values not specified are now set to -1, which means those + * aspects of the current display mode are not changed in + * fghChangeDisplayMode() above. + */ + fgState.GameModeSize.X = width; + fgState.GameModeSize.Y = height; + fgState.GameModeDepth = depth; + fgState.GameModeRefresh = refresh; } -- 1.7.10.4