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 * TODO BEFORE THE STABLE RELEASE:
34 * glutGameModeString() -- missing
35 * glutEnterGameMode() -- X11 version
36 * glutLeaveGameMode() -- is that correct?
37 * glutGameModeGet() -- is that correct?
41 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
42 extern void fgPlatformRememberState( void );
43 extern void fgPlatformRestoreState( void );
44 extern GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest );
45 extern void fgPlatformEnterGameMode( void );
46 extern void fgPlatformLeaveGameMode( void );
49 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
52 * Sets the game mode display string
54 void FGAPIENTRY glutGameModeString( const char* string )
56 int width = -1, height = -1, depth = -1, refresh = -1;
58 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeString" );
61 * This one seems a bit easier than glutInitDisplayString. The bad thing
62 * about it that I was unable to find the game mode string definition, so
63 * that I assumed it is: "[width]x[height]:[depth]@[refresh rate]", which
64 * appears in all GLUT game mode programs I have seen to date.
66 if( sscanf( string, "%ix%i:%i@%i", &width, &height, &depth, &refresh ) !=
68 if( sscanf( string, "%ix%i:%i", &width, &height, &depth ) != 3 )
69 if( sscanf( string, "%ix%i@%i", &width, &height, &refresh ) != 3 )
70 if( sscanf( string, "%ix%i", &width, &height ) != 2 )
71 if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 )
72 if( sscanf( string, ":%i", &depth ) != 1 )
73 if( sscanf( string, "@%i", &refresh ) != 1 )
75 "unable to parse game mode string `%s'",
79 /* All values not specified are now set to -1, which means those
80 * aspects of the current display mode are not changed in
81 * fgPlatformChangeDisplayMode() above.
83 fgState.GameModeSize.X = width;
84 fgState.GameModeSize.Y = height;
85 fgState.GameModeDepth = depth;
86 fgState.GameModeRefresh = refresh;
92 * Enters the game mode
94 int FGAPIENTRY glutEnterGameMode( void )
96 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" );
98 if( fgStructure.GameModeWindow )
99 fgAddToWindowDestroyList( fgStructure.GameModeWindow );
101 fgPlatformRememberState( );
103 if( ! fgPlatformChangeDisplayMode( GL_FALSE ) )
105 fgWarning( "failed to change screen settings" );
109 fgStructure.GameModeWindow = fgCreateWindow(
110 NULL, "FREEGLUT", GL_TRUE, 0, 0,
111 GL_TRUE, fgState.GameModeSize.X, fgState.GameModeSize.Y,
115 fgStructure.GameModeWindow->State.Width = fgState.GameModeSize.X;
116 fgStructure.GameModeWindow->State.Height = fgState.GameModeSize.Y;
117 fgStructure.GameModeWindow->State.NeedToResize = GL_TRUE;
119 fgPlatformEnterGameMode();
121 return fgStructure.GameModeWindow->ID;
125 * Leaves the game mode
127 void FGAPIENTRY glutLeaveGameMode( void )
129 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveGameMode" );
131 freeglut_return_if_fail( fgStructure.GameModeWindow );
133 fgAddToWindowDestroyList( fgStructure.GameModeWindow );
134 fgStructure.GameModeWindow = NULL;
136 fgPlatformLeaveGameMode();
138 fgPlatformRestoreState();
142 * Returns information concerning the freeglut game mode
144 int FGAPIENTRY glutGameModeGet( GLenum eWhat )
146 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeGet" );
150 case GLUT_GAME_MODE_ACTIVE:
151 return !!fgStructure.GameModeWindow;
153 case GLUT_GAME_MODE_POSSIBLE:
154 return fgPlatformChangeDisplayMode( GL_TRUE );
156 case GLUT_GAME_MODE_WIDTH:
157 return fgState.GameModeSize.X;
159 case GLUT_GAME_MODE_HEIGHT:
160 return fgState.GameModeSize.Y;
162 case GLUT_GAME_MODE_PIXEL_DEPTH:
163 return fgState.GameModeDepth;
165 case GLUT_GAME_MODE_REFRESH_RATE:
166 return fgState.GameModeRefresh;
168 case GLUT_GAME_MODE_DISPLAY_CHANGED:
170 * This is true if the game mode has been activated successfully..
172 return !!fgStructure.GameModeWindow;
175 fgWarning( "Unknown gamemode get: %d", eWhat );
179 /*** END OF FILE ***/