2 * freeglut_gamemode.c
\r
4 * The game mode handling code.
\r
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
\r
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
\r
8 * Creation date: Thu Dec 16 1999
\r
10 * Permission is hereby granted, free of charge, to any person obtaining a
\r
11 * copy of this software and associated documentation files (the "Software"),
\r
12 * to deal in the Software without restriction, including without limitation
\r
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
14 * and/or sell copies of the Software, and to permit persons to whom the
\r
15 * Software is furnished to do so, subject to the following conditions:
\r
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
\r
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 #include <GL/freeglut.h>
\r
29 #include "freeglut_internal.h"
\r
32 * TODO BEFORE THE STABLE RELEASE:
\r
34 * glutGameModeString() -- missing
\r
35 * glutEnterGameMode() -- X11 version
\r
36 * glutLeaveGameMode() -- is that correct?
\r
37 * glutGameModeGet() -- is that correct?
\r
41 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
\r
42 extern void fgPlatformRememberState( void );
\r
43 extern void fgPlatformRestoreState( void );
\r
44 extern GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest );
\r
45 extern void fgPlatformEnterGameMode( void );
\r
46 extern void fgPlatformLeaveGameMode( void );
\r
49 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
\r
52 * Sets the game mode display string
\r
54 void FGAPIENTRY glutGameModeString( const char* string )
\r
56 int width = -1, height = -1, depth = -1, refresh = -1;
\r
58 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeString" );
\r
61 * This one seems a bit easier than glutInitDisplayString. The bad thing
\r
62 * about it that I was unable to find the game mode string definition, so
\r
63 * that I assumed it is: "[width]x[height]:[depth]@[refresh rate]", which
\r
64 * appears in all GLUT game mode programs I have seen to date.
\r
66 if( sscanf( string, "%ix%i:%i@%i", &width, &height, &depth, &refresh ) !=
\r
68 if( sscanf( string, "%ix%i:%i", &width, &height, &depth ) != 3 )
\r
69 if( sscanf( string, "%ix%i@%i", &width, &height, &refresh ) != 3 )
\r
70 if( sscanf( string, "%ix%i", &width, &height ) != 2 )
\r
71 if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 )
\r
72 if( sscanf( string, ":%i", &depth ) != 1 )
\r
73 if( sscanf( string, "@%i", &refresh ) != 1 )
\r
75 "unable to parse game mode string `%s'",
\r
79 /* All values not specified are now set to -1, which means those
\r
80 * aspects of the current display mode are not changed in
\r
81 * fgPlatformChangeDisplayMode() above.
\r
83 fgState.GameModeSize.X = width;
\r
84 fgState.GameModeSize.Y = height;
\r
85 fgState.GameModeDepth = depth;
\r
86 fgState.GameModeRefresh = refresh;
\r
92 * Enters the game mode
\r
94 int FGAPIENTRY glutEnterGameMode( void )
\r
96 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" );
\r
98 if( fgStructure.GameModeWindow )
\r
99 fgAddToWindowDestroyList( fgStructure.GameModeWindow );
\r
101 fgPlatformRememberState( );
\r
103 if( ! fgPlatformChangeDisplayMode( GL_FALSE ) )
\r
105 fgWarning( "failed to change screen settings" );
\r
109 fgStructure.GameModeWindow = fgCreateWindow(
\r
110 NULL, "FREEGLUT", GL_TRUE, 0, 0,
\r
111 GL_TRUE, fgState.GameModeSize.X, fgState.GameModeSize.Y,
\r
115 fgStructure.GameModeWindow->State.Width = fgState.GameModeSize.X;
\r
116 fgStructure.GameModeWindow->State.Height = fgState.GameModeSize.Y;
\r
117 fgStructure.GameModeWindow->State.NeedToResize = GL_TRUE;
\r
119 fgPlatformEnterGameMode();
\r
121 return fgStructure.GameModeWindow->ID;
\r
125 * Leaves the game mode
\r
127 void FGAPIENTRY glutLeaveGameMode( void )
\r
129 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveGameMode" );
\r
131 freeglut_return_if_fail( fgStructure.GameModeWindow );
\r
133 fgAddToWindowDestroyList( fgStructure.GameModeWindow );
\r
134 fgStructure.GameModeWindow = NULL;
\r
136 fgPlatformLeaveGameMode();
\r
138 fgPlatformRestoreState();
\r
142 * Returns information concerning the freeglut game mode
\r
144 int FGAPIENTRY glutGameModeGet( GLenum eWhat )
\r
146 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeGet" );
\r
150 case GLUT_GAME_MODE_ACTIVE:
\r
151 return !!fgStructure.GameModeWindow;
\r
153 case GLUT_GAME_MODE_POSSIBLE:
\r
154 return fgPlatformChangeDisplayMode( GL_TRUE );
\r
156 case GLUT_GAME_MODE_WIDTH:
\r
157 return fgState.GameModeSize.X;
\r
159 case GLUT_GAME_MODE_HEIGHT:
\r
160 return fgState.GameModeSize.Y;
\r
162 case GLUT_GAME_MODE_PIXEL_DEPTH:
\r
163 return fgState.GameModeDepth;
\r
165 case GLUT_GAME_MODE_REFRESH_RATE:
\r
166 return fgState.GameModeRefresh;
\r
168 case GLUT_GAME_MODE_DISPLAY_CHANGED:
\r
170 * This is true if the game mode has been activated successfully..
\r
172 return !!fgStructure.GameModeWindow;
\r
175 fgWarning( "Unknown gamemode get: %d", eWhat );
\r
179 /*** END OF FILE ***/
\r