2 * freeglut_gamemode_mswin.c
4 * The Windows-specific mouse cursor related stuff.
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
7 * Written by John F. Fay, <fayjf@sourceforge.net>
8 * Creation date: Thu Jan 19, 2012
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 * Remembers the current visual settings, so that
33 * we can change them and restore later...
35 void fgPlatformRememberState( void )
37 /* Grab the current desktop settings... */
39 /* hack to get around my stupid cross-gcc headers */
40 #define FREEGLUT_ENUM_CURRENT_SETTINGS -1
42 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS,
43 &fgDisplay.pDisplay.DisplayMode );
45 /* Make sure we will be restoring all settings needed */
46 fgDisplay.pDisplay.DisplayMode.dmFields |=
47 DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
52 * Restores the previously remembered visual settings
54 void fgPlatformRestoreState( void )
56 /* Restore the previously remembered desktop display settings */
57 ChangeDisplaySettingsEx( fgDisplay.pDisplay.DisplayName,&fgDisplay.pDisplay.DisplayMode, 0,0,0 );
64 * Changes the current display mode to match user's settings
66 GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest )
68 GLboolean success = GL_FALSE;
71 char displayMode[300];
75 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, -1, &devMode );
78 if (fgState.GameModeSize.X!=-1)
80 devMode.dmPelsWidth = fgState.GameModeSize.X;
81 devMode.dmFields |= DM_PELSWIDTH;
83 if (fgState.GameModeSize.Y!=-1)
85 devMode.dmPelsHeight = fgState.GameModeSize.Y;
86 devMode.dmFields |= DM_PELSHEIGHT;
88 if (fgState.GameModeDepth!=-1)
90 devMode.dmBitsPerPel = fgState.GameModeDepth;
91 devMode.dmFields |= DM_BITSPERPEL;
93 if (fgState.GameModeRefresh!=-1)
95 devMode.dmDisplayFrequency = fgState.GameModeRefresh;
96 devMode.dmFields |= DM_DISPLAYFREQUENCY;
99 switch ( ChangeDisplaySettingsEx(fgDisplay.pDisplay.DisplayName, &devMode, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) )
101 case DISP_CHANGE_SUCCESSFUL:
106 /* update vars in case if windows switched to proper mode */
107 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode );
108 fgState.GameModeSize.X = devMode.dmPelsWidth;
109 fgState.GameModeSize.Y = devMode.dmPelsHeight;
110 fgState.GameModeDepth = devMode.dmBitsPerPel;
111 fgState.GameModeRefresh = devMode.dmDisplayFrequency;
114 case DISP_CHANGE_RESTART:
115 fggmstr = "The computer must be restarted for the graphics mode to work.";
117 case DISP_CHANGE_BADFLAGS:
118 fggmstr = "An invalid set of flags was passed in.";
120 case DISP_CHANGE_BADPARAM:
121 fggmstr = "An invalid parameter was passed in. This can include an invalid flag or combination of flags.";
123 case DISP_CHANGE_FAILED:
124 fggmstr = "The display driver failed the specified graphics mode.";
126 case DISP_CHANGE_BADMODE:
127 fggmstr = "The graphics mode is not supported.";
130 fggmstr = "Unknown error in graphics mode???"; /* dunno if it is possible,MSDN does not mention any other error */
136 /* I'd rather get info whats going on in my program than wonder about */
137 /* magic happenings behind my back, its lib for devels at last ;) */
139 /* append display mode to error to make things more informative */
140 sprintf(displayMode,"%s Problem with requested mode: %ix%i:%i@%i", fggmstr, devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmDisplayFrequency);
141 fgWarning(displayMode);
147 void fgPlatformEnterGameMode( void )
151 void fgPlatformLeaveGameMode( void )