4 * The game mode handling code.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Thu Dec 16 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <GL/freeglut.h>
29 #include "fg_internal.h"
32 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
33 extern void fgPlatformRememberState( void );
34 extern void fgPlatformRestoreState( void );
35 extern GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest );
36 extern void fgPlatformEnterGameMode( void );
37 extern void fgPlatformLeaveGameMode( void );
40 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
43 * Sets the game mode display string
45 void FGAPIENTRY glutGameModeString( const char* string )
47 int width = -1, height = -1, depth = -1, refresh = -1;
49 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeString" );
52 * This one seems a bit easier than glutInitDisplayString. The bad thing
53 * about it that I was unable to find the game mode string definition, so
54 * that I assumed it is: "[width]x[height]:[depth]@[refresh rate]", which
55 * appears in all GLUT game mode programs I have seen to date.
57 if( sscanf( string, "%ix%i:%i@%i", &width, &height, &depth, &refresh ) !=
59 if( sscanf( string, "%ix%i:%i", &width, &height, &depth ) != 3 )
60 if( sscanf( string, "%ix%i@%i", &width, &height, &refresh ) != 3 )
61 if( sscanf( string, "%ix%i", &width, &height ) != 2 )
62 if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 )
63 if( sscanf( string, ":%i", &depth ) != 1 )
64 if( sscanf( string, "@%i", &refresh ) != 1 )
66 "unable to parse game mode string `%s'",
70 /* All values not specified are now set to -1, which means those
71 * aspects of the current display mode are not changed in
72 * fgPlatformChangeDisplayMode() above.
74 fgState.GameModeSize.X = width;
75 fgState.GameModeSize.Y = height;
76 fgState.GameModeDepth = depth;
77 fgState.GameModeRefresh = refresh;
83 * Enters the game mode
85 int FGAPIENTRY glutEnterGameMode( void )
87 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" );
89 if( fgStructure.GameModeWindow )
90 fgAddToWindowDestroyList( fgStructure.GameModeWindow );
92 fgPlatformRememberState( );
94 if( ! fgPlatformChangeDisplayMode( GL_FALSE ) )
96 fgWarning( "failed to change screen settings" );
100 fgStructure.GameModeWindow = fgCreateWindow(
101 NULL, "FREEGLUT", GL_TRUE, 0, 0,
102 GL_TRUE, fgState.GameModeSize.X, fgState.GameModeSize.Y,
108 fgPlatformEnterGameMode();
110 return fgStructure.GameModeWindow->ID;
114 * Leaves the game mode
116 void FGAPIENTRY glutLeaveGameMode( void )
118 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveGameMode" );
120 freeglut_return_if_fail( fgStructure.GameModeWindow );
122 fgAddToWindowDestroyList( fgStructure.GameModeWindow );
123 fgStructure.GameModeWindow = NULL;
125 fgPlatformLeaveGameMode();
127 fgPlatformRestoreState();
131 * Returns information concerning the freeglut game mode
133 int FGAPIENTRY glutGameModeGet( GLenum eWhat )
135 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeGet" );
139 case GLUT_GAME_MODE_ACTIVE:
140 return !!fgStructure.GameModeWindow;
142 case GLUT_GAME_MODE_POSSIBLE:
143 return fgPlatformChangeDisplayMode( GL_TRUE );
145 case GLUT_GAME_MODE_WIDTH:
146 return fgState.GameModeSize.X;
148 case GLUT_GAME_MODE_HEIGHT:
149 return fgState.GameModeSize.Y;
151 case GLUT_GAME_MODE_PIXEL_DEPTH:
152 return fgState.GameModeDepth;
154 case GLUT_GAME_MODE_REFRESH_RATE:
155 return fgState.GameModeRefresh;
157 case GLUT_GAME_MODE_DISPLAY_CHANGED:
159 * This is true if the game mode has been activated successfully..
161 return !!fgStructure.GameModeWindow;
164 fgWarning( "Unknown gamemode get: %d", eWhat );
168 /*** END OF FILE ***/