Setting the line endings and keywords on a bunch of new text files
[freeglut] / src / Common / freeglut_gamemode.c
index 8a923eb..d9b71f8 100644 (file)
-/*\r
- * freeglut_gamemode.c\r
- *\r
- * The game mode handling code.\r
- *\r
- * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.\r
- * Written by Pawel W. Olszta, <olszta@sourceforge.net>\r
- * Creation date: Thu Dec 16 1999\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
- * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-#include <GL/freeglut.h>\r
-#include "freeglut_internal.h"\r
-\r
-/*\r
- * TODO BEFORE THE STABLE RELEASE:\r
- *\r
- *  glutGameModeString()    -- missing\r
- *  glutEnterGameMode()     -- X11 version\r
- *  glutLeaveGameMode()     -- is that correct?\r
- *  glutGameModeGet()       -- is that correct?\r
- */\r
-\r
-\r
-/* -- PRIVATE FUNCTIONS ---------------------------------------------------- */\r
-extern void fgPlatformRememberState( void );\r
-extern void fgPlatformRestoreState( void );\r
-extern GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest );\r
-extern void fgPlatformEnterGameMode( void );\r
-extern void fgPlatformLeaveGameMode( void );\r
-\r
-\r
-/* -- INTERFACE FUNCTIONS -------------------------------------------------- */\r
-\r
-/*\r
- * Sets the game mode display string\r
- */\r
-void FGAPIENTRY glutGameModeString( const char* string )\r
-{\r
-    int width = -1, height = -1, depth = -1, refresh = -1;\r
-\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeString" );\r
-\r
-    /*\r
-     * This one seems a bit easier than glutInitDisplayString. The bad thing\r
-     * about it that I was unable to find the game mode string definition, so\r
-     * that I assumed it is: "[width]x[height]:[depth]@[refresh rate]", which\r
-     * appears in all GLUT game mode programs I have seen to date.\r
-     */\r
-    if( sscanf( string, "%ix%i:%i@%i", &width, &height, &depth, &refresh ) !=\r
-        4 )\r
-        if( sscanf( string, "%ix%i:%i", &width, &height, &depth ) != 3 )\r
-            if( sscanf( string, "%ix%i@%i", &width, &height, &refresh ) != 3 )\r
-                if( sscanf( string, "%ix%i", &width, &height ) != 2 )\r
-                    if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 )\r
-                        if( sscanf( string, ":%i", &depth ) != 1 )\r
-                            if( sscanf( string, "@%i", &refresh ) != 1 )\r
-                                fgWarning(\r
-                                    "unable to parse game mode string `%s'",\r
-                                    string\r
-                                );\r
-\r
-    /* All values not specified are now set to -1, which means those\r
-     * aspects of the current display mode are not changed in\r
-     * fgPlatformChangeDisplayMode() above.\r
-     */\r
-    fgState.GameModeSize.X  = width;\r
-    fgState.GameModeSize.Y  = height;\r
-    fgState.GameModeDepth   = depth;\r
-    fgState.GameModeRefresh = refresh;\r
-}\r
-\r
-\r
-\r
-/*\r
- * Enters the game mode\r
- */\r
-int FGAPIENTRY glutEnterGameMode( void )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" );\r
-\r
-    if( fgStructure.GameModeWindow )\r
-        fgAddToWindowDestroyList( fgStructure.GameModeWindow );\r
-    else\r
-        fgPlatformRememberState( );\r
-\r
-    if( ! fgPlatformChangeDisplayMode( GL_FALSE ) )\r
-    {\r
-        fgWarning( "failed to change screen settings" );\r
-        return 0;\r
-    }\r
-\r
-    fgStructure.GameModeWindow = fgCreateWindow(\r
-        NULL, "FREEGLUT", GL_TRUE, 0, 0,\r
-        GL_TRUE, fgState.GameModeSize.X, fgState.GameModeSize.Y,\r
-        GL_TRUE, GL_FALSE\r
-    );\r
-\r
-    fgStructure.GameModeWindow->State.Width  = fgState.GameModeSize.X;\r
-    fgStructure.GameModeWindow->State.Height = fgState.GameModeSize.Y;\r
-    fgStructure.GameModeWindow->State.NeedToResize = GL_TRUE;\r
-\r
-    fgPlatformEnterGameMode();\r
-\r
-    return fgStructure.GameModeWindow->ID;\r
-}\r
-\r
-/*\r
- * Leaves the game mode\r
- */\r
-void FGAPIENTRY glutLeaveGameMode( void )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveGameMode" );\r
-\r
-    freeglut_return_if_fail( fgStructure.GameModeWindow );\r
-\r
-    fgAddToWindowDestroyList( fgStructure.GameModeWindow );\r
-    fgStructure.GameModeWindow = NULL;\r
-\r
-    fgPlatformLeaveGameMode();\r
-\r
-    fgPlatformRestoreState();\r
-}\r
-\r
-/*\r
- * Returns information concerning the freeglut game mode\r
- */\r
-int FGAPIENTRY glutGameModeGet( GLenum eWhat )\r
-{\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeGet" );\r
-\r
-    switch( eWhat )\r
-    {\r
-    case GLUT_GAME_MODE_ACTIVE:\r
-        return !!fgStructure.GameModeWindow;\r
-\r
-    case GLUT_GAME_MODE_POSSIBLE:\r
-        return fgPlatformChangeDisplayMode( GL_TRUE );\r
-\r
-    case GLUT_GAME_MODE_WIDTH:\r
-        return fgState.GameModeSize.X;\r
-\r
-    case GLUT_GAME_MODE_HEIGHT:\r
-        return fgState.GameModeSize.Y;\r
-\r
-    case GLUT_GAME_MODE_PIXEL_DEPTH:\r
-        return fgState.GameModeDepth;\r
-\r
-    case GLUT_GAME_MODE_REFRESH_RATE:\r
-        return fgState.GameModeRefresh;\r
-\r
-    case GLUT_GAME_MODE_DISPLAY_CHANGED:\r
-        /*\r
-         * This is true if the game mode has been activated successfully..\r
-         */\r
-        return !!fgStructure.GameModeWindow;\r
-    }\r
-\r
-    fgWarning( "Unknown gamemode get: %d", eWhat );\r
-    return -1;\r
-}\r
-\r
-/*** END OF FILE ***/\r
+/*
+ * freeglut_gamemode.c
+ *
+ * The game mode handling code.
+ *
+ * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
+ * Written by Pawel W. Olszta, <olszta@sourceforge.net>
+ * Creation date: Thu Dec 16 1999
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <GL/freeglut.h>
+#include "freeglut_internal.h"
+
+/*
+ * TODO BEFORE THE STABLE RELEASE:
+ *
+ *  glutGameModeString()    -- missing
+ *  glutEnterGameMode()     -- X11 version
+ *  glutLeaveGameMode()     -- is that correct?
+ *  glutGameModeGet()       -- is that correct?
+ */
+
+
+/* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
+extern void fgPlatformRememberState( void );
+extern void fgPlatformRestoreState( void );
+extern GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest );
+extern void fgPlatformEnterGameMode( void );
+extern void fgPlatformLeaveGameMode( void );
+
+
+/* -- INTERFACE FUNCTIONS -------------------------------------------------- */
+
+/*
+ * Sets the game mode display string
+ */
+void FGAPIENTRY glutGameModeString( const char* string )
+{
+    int width = -1, height = -1, depth = -1, refresh = -1;
+
+    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
+     * that I assumed it is: "[width]x[height]:[depth]@[refresh rate]", which
+     * appears in all GLUT game mode programs I have seen to date.
+     */
+    if( sscanf( string, "%ix%i:%i@%i", &width, &height, &depth, &refresh ) !=
+        4 )
+        if( sscanf( string, "%ix%i:%i", &width, &height, &depth ) != 3 )
+            if( sscanf( string, "%ix%i@%i", &width, &height, &refresh ) != 3 )
+                if( sscanf( string, "%ix%i", &width, &height ) != 2 )
+                    if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 )
+                        if( sscanf( string, ":%i", &depth ) != 1 )
+                            if( sscanf( string, "@%i", &refresh ) != 1 )
+                                fgWarning(
+                                    "unable to parse game mode string `%s'",
+                                    string
+                                );
+
+    /* All values not specified are now set to -1, which means those
+     * aspects of the current display mode are not changed in
+     * fgPlatformChangeDisplayMode() above.
+     */
+    fgState.GameModeSize.X  = width;
+    fgState.GameModeSize.Y  = height;
+    fgState.GameModeDepth   = depth;
+    fgState.GameModeRefresh = refresh;
+}
+
+
+
+/*
+ * Enters the game mode
+ */
+int FGAPIENTRY glutEnterGameMode( void )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" );
+
+    if( fgStructure.GameModeWindow )
+        fgAddToWindowDestroyList( fgStructure.GameModeWindow );
+    else
+        fgPlatformRememberState( );
+
+    if( ! fgPlatformChangeDisplayMode( GL_FALSE ) )
+    {
+        fgWarning( "failed to change screen settings" );
+        return 0;
+    }
+
+    fgStructure.GameModeWindow = fgCreateWindow(
+        NULL, "FREEGLUT", GL_TRUE, 0, 0,
+        GL_TRUE, fgState.GameModeSize.X, fgState.GameModeSize.Y,
+        GL_TRUE, GL_FALSE
+    );
+
+    fgStructure.GameModeWindow->State.Width  = fgState.GameModeSize.X;
+    fgStructure.GameModeWindow->State.Height = fgState.GameModeSize.Y;
+    fgStructure.GameModeWindow->State.NeedToResize = GL_TRUE;
+
+    fgPlatformEnterGameMode();
+
+    return fgStructure.GameModeWindow->ID;
+}
+
+/*
+ * Leaves the game mode
+ */
+void FGAPIENTRY glutLeaveGameMode( void )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveGameMode" );
+
+    freeglut_return_if_fail( fgStructure.GameModeWindow );
+
+    fgAddToWindowDestroyList( fgStructure.GameModeWindow );
+    fgStructure.GameModeWindow = NULL;
+
+    fgPlatformLeaveGameMode();
+
+    fgPlatformRestoreState();
+}
+
+/*
+ * Returns information concerning the freeglut game mode
+ */
+int FGAPIENTRY glutGameModeGet( GLenum eWhat )
+{
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeGet" );
+
+    switch( eWhat )
+    {
+    case GLUT_GAME_MODE_ACTIVE:
+        return !!fgStructure.GameModeWindow;
+
+    case GLUT_GAME_MODE_POSSIBLE:
+        return fgPlatformChangeDisplayMode( GL_TRUE );
+
+    case GLUT_GAME_MODE_WIDTH:
+        return fgState.GameModeSize.X;
+
+    case GLUT_GAME_MODE_HEIGHT:
+        return fgState.GameModeSize.Y;
+
+    case GLUT_GAME_MODE_PIXEL_DEPTH:
+        return fgState.GameModeDepth;
+
+    case GLUT_GAME_MODE_REFRESH_RATE:
+        return fgState.GameModeRefresh;
+
+    case GLUT_GAME_MODE_DISPLAY_CHANGED:
+        /*
+         * This is true if the game mode has been activated successfully..
+         */
+        return !!fgStructure.GameModeWindow;
+    }
+
+    fgWarning( "Unknown gamemode get: %d", eWhat );
+    return -1;
+}
+
+/*** END OF FILE ***/