X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_gamemode.c;h=7d5a1ef11e24b9a82b07101d9bd711dacb13dc80;hb=c24efb9241080a043193b67c6a9718312fed8d07;hp=5f934315aaf0b88ed9fd887437d13880ac7d62ae;hpb=4fa63bbb5637f30db8eec9de49c0b2c4830cb866;p=freeglut diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index 5f93431..7d5a1ef 100644 --- a/src/freeglut_gamemode.c +++ b/src/freeglut_gamemode.c @@ -25,10 +25,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include "freeglut_internal.h" @@ -48,7 +44,7 @@ * Remembers the current visual settings, so that * we can change them and restore later... */ -void fghRememberState( void ) +static void fghRememberState( void ) { #if TARGET_HOST_UNIX_X11 @@ -96,7 +92,7 @@ void fghRememberState( void ) ); if( !fgDisplay.DisplayModeValid ) - fgWarning( "Runtime use of XF86VidModeGetModeLine failed.\n" ); + fgWarning( "Runtime use of XF86VidModeGetModeLine failed." ); # else /* @@ -127,7 +123,7 @@ void fghRememberState( void ) /* * Restores the previously remembered visual settings */ -void fghRestoreState( void ) +static void fghRestoreState( void ) { #if TARGET_HOST_UNIX_X11 @@ -184,9 +180,10 @@ void fghRestoreState( void ) */ XFlush( fgDisplay.Display ); - return; + break; } } + XFree( displayModes ); } # else @@ -207,7 +204,7 @@ void fghRestoreState( void ) /* * Checks the display mode settings against user's preferences */ -GLboolean fghCheckDisplayMode( int width, int height, int depth, int refresh ) +static GLboolean fghCheckDisplayMode( int width, int height, int depth, int refresh ) { /* The desired values should be stored in fgState structure... */ return ( width == fgState.GameModeSize.X ) && @@ -219,8 +216,9 @@ GLboolean fghCheckDisplayMode( int width, int height, int depth, int refresh ) /* * Changes the current display mode to match user's settings */ -GLboolean fghChangeDisplayMode( GLboolean haveToTest ) +static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) { + GLboolean success = GL_FALSE; #if TARGET_HOST_UNIX_X11 /* @@ -236,7 +234,7 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest ) if( haveToTest || fgDisplay.DisplayModeValid ) { XF86VidModeModeInfo** displayModes; - int i, displayModesCount; + int i, ignoreRefreshRate, displayModesCount; XF86VidModeGetAllModeLines( fgDisplay.Display, @@ -245,29 +243,35 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest ) &displayModes ); - /* Check every of the modes looking for one that matches our demands */ - for( i = 0; i < displayModesCount; i++ ) + /* + * Check every of the modes looking for one that matches our demands, + * ignoring the refresh rate if no exact match could be found. + */ + for( ignoreRefreshRate = 0; + !success && ( ignoreRefreshRate <= 1 ); + ignoreRefreshRate++) { - if( fghCheckDisplayMode( displayModes[ i ]->hdisplay, - displayModes[ i ]->vdisplay, - fgState.GameModeDepth, - fgState.GameModeRefresh ) ) + for( i = 0; + !success && ( i < displayModesCount ); + i++ ) { - if( haveToTest ) - return GL_TRUE; - /* OKi, this is the display mode we have been looking for... */ - XF86VidModeSwitchToMode( - fgDisplay.Display, - fgDisplay.Screen, - displayModes[ i ] - ); - return GL_TRUE; + /* Compute the displays refresh rate, dotclock comes in kHz. */ + int refresh = ( displayModes[ i ]->dotclock * 1000 ) / + ( displayModes[ i ]->htotal * displayModes[ i ]->vtotal ); + + success = fghCheckDisplayMode( displayModes[ i ]->hdisplay, + displayModes[ i ]->vdisplay, + fgState.GameModeDepth, + ( ignoreRefreshRate ? fgState.GameModeRefresh : refresh ) ); } } - } - /* Something must have gone wrong */ - return GL_FALSE; + if( !haveToTest && success ) { + XF86VidModeSwitchToMode( fgDisplay.Display, fgDisplay.Screen, displayModes[ i ] ); + } + + XFree( displayModes ); + } # else /* @@ -279,7 +283,6 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest ) #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE unsigned int displayModes = 0, mode = 0xffffffff; - GLboolean success = GL_FALSE; /* HDC desktopDC; */ DEVMODE devMode; @@ -345,9 +348,9 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest ) } } - return success; - #endif + + return success; } @@ -360,6 +363,8 @@ void FGAPIENTRY glutGameModeString( const char* string ) { int width = 640, height = 480, depth = 16, refresh = 72; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeString" ); + /* * This one seems a bit easier than glutInitDisplayString. The bad thing * about it that I was unable to find the game mode string definition, so @@ -391,6 +396,8 @@ void FGAPIENTRY glutGameModeString( const char* string ) */ int FGAPIENTRY glutEnterGameMode( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" ); + if( fgStructure.GameMode ) fgAddToWindowDestroyList( fgStructure.GameMode ); else @@ -509,12 +516,13 @@ int FGAPIENTRY glutEnterGameMode( void ) */ void FGAPIENTRY glutLeaveGameMode( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveGameMode" ); + freeglut_return_if_fail( fgStructure.GameMode ); fgStructure.GameMode->State.IsGameMode = GL_FALSE; fgAddToWindowDestroyList( fgStructure.GameMode ); - fgStructure.GameMode = NULL; #if TARGET_HOST_UNIX_X11 @@ -532,6 +540,8 @@ void FGAPIENTRY glutLeaveGameMode( void ) */ int FGAPIENTRY glutGameModeGet( GLenum eWhat ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeGet" ); + switch( eWhat ) { case GLUT_GAME_MODE_ACTIVE: @@ -559,6 +569,7 @@ int FGAPIENTRY glutGameModeGet( GLenum eWhat ) return !!fgStructure.GameMode; } + fgWarning( "Unknown gamemode get: %d", eWhat ); return -1; }