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 * Changes to requested devmode, if it doesn't match current mode
34 GLboolean fghChangeDisplayMode(GLboolean haveToTest, DEVMODE *devModeRequested)
36 GLboolean success = GL_FALSE;
37 DEVMODE devModeCurrent;
39 char displayMode[300];
41 /* Get current display mode */
42 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devModeCurrent );
43 /* Now see if requested matches current mode, then we're done
44 * There's only four fields we touch:
48 * - dmDisplayFrequency
50 if (devModeCurrent.dmPelsWidth ==devModeRequested->dmPelsWidth &&
51 devModeCurrent.dmPelsHeight ==devModeRequested->dmPelsHeight &&
52 devModeCurrent.dmBitsPerPel ==devModeRequested->dmBitsPerPel &&
53 devModeCurrent.dmDisplayFrequency==devModeRequested->dmDisplayFrequency)
57 /* update vars in case if actual switch was requested */
58 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devModeCurrent );
59 fgState.GameModeSize.X = devModeCurrent.dmPelsWidth;
60 fgState.GameModeSize.Y = devModeCurrent.dmPelsHeight;
61 fgState.GameModeDepth = devModeCurrent.dmBitsPerPel;
62 fgState.GameModeRefresh = devModeCurrent.dmDisplayFrequency;
70 /* Ok, we do have a mode switch to perform/test */
71 switch ( ChangeDisplaySettingsEx(fgDisplay.pDisplay.DisplayName, devModeRequested, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) )
73 case DISP_CHANGE_SUCCESSFUL:
78 /* update vars in case if windows switched to proper mode */
79 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devModeCurrent );
80 fgState.GameModeSize.X = devModeCurrent.dmPelsWidth;
81 fgState.GameModeSize.Y = devModeCurrent.dmPelsHeight;
82 fgState.GameModeDepth = devModeCurrent.dmBitsPerPel;
83 fgState.GameModeRefresh = devModeCurrent.dmDisplayFrequency;
86 case DISP_CHANGE_RESTART:
87 fggmstr = "The computer must be restarted for the graphics mode to work.";
89 case DISP_CHANGE_BADFLAGS:
90 fggmstr = "An invalid set of flags was passed in.";
92 case DISP_CHANGE_BADPARAM:
93 fggmstr = "An invalid parameter was passed in. This can include an invalid flag or combination of flags.";
95 case DISP_CHANGE_FAILED:
96 fggmstr = "The display driver failed the specified graphics mode.";
98 case DISP_CHANGE_BADMODE:
99 fggmstr = "The graphics mode is not supported.";
102 fggmstr = "Unknown error in graphics mode???"; /* dunno if it is possible, MSDN does not mention any other error */
108 /* I'd rather get info whats going on in my program than wonder about */
109 /* what magic happens behind my back, its lib for devels after all ;) */
111 /* append display mode to error to make things more informative */
112 sprintf(displayMode,"%s Problem with requested mode: %lux%lu:%lu@%lu", fggmstr, devModeRequested->dmPelsWidth, devModeRequested->dmPelsHeight, devModeRequested->dmBitsPerPel, devModeRequested->dmDisplayFrequency);
113 fgWarning(displayMode);
120 * Remembers the current visual settings, so that
121 * we can change them and restore later...
123 void fgPlatformRememberState( void )
125 /* Grab the current desktop settings... */
126 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS,
127 &fgDisplay.pDisplay.DisplayMode );
129 /* Make sure we will be restoring all settings needed */
130 fgDisplay.pDisplay.DisplayMode.dmFields |=
131 DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
136 * Restores the previously remembered visual settings
138 void fgPlatformRestoreState( void )
140 /* Restore the previously remembered desktop display settings */
141 fghChangeDisplayMode(GL_FALSE,&fgDisplay.pDisplay.DisplayMode);
148 * Changes the current display mode to match user's settings
150 GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest )
154 /* Get current display mode */
155 EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devMode );
156 devMode.dmFields = 0;
158 if (fgState.GameModeSize.X!=-1)
160 devMode.dmPelsWidth = fgState.GameModeSize.X;
161 devMode.dmFields |= DM_PELSWIDTH;
163 if (fgState.GameModeSize.Y!=-1)
165 devMode.dmPelsHeight = fgState.GameModeSize.Y;
166 devMode.dmFields |= DM_PELSHEIGHT;
168 if (fgState.GameModeDepth!=-1)
170 devMode.dmBitsPerPel = fgState.GameModeDepth;
171 devMode.dmFields |= DM_BITSPERPEL;
173 if (fgState.GameModeRefresh!=-1)
175 devMode.dmDisplayFrequency = fgState.GameModeRefresh;
176 devMode.dmFields |= DM_DISPLAYFREQUENCY;
179 return fghChangeDisplayMode(haveToTest, &devMode);
182 void fgPlatformEnterGameMode( void )
186 void fgPlatformLeaveGameMode( void )