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