when entering game mode, now avoiding call to ChangeDisplaySettingsEx

when not necessary. Avoids flashing of the screen



git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1453 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2012-11-20 02:17:31 +00:00
parent 2de980d6b4
commit d01664a8bf

View File

@ -29,74 +29,47 @@
#include "../fg_internal.h" #include "../fg_internal.h"
/* /*
* Remembers the current visual settings, so that *
* we can change them and restore later... *
*/ */
void fgPlatformRememberState( void ) GLboolean fghPlatformChangeDisplayMode(GLboolean haveToTest, DEVMODE *devModeRequested)
{
/* Grab the current desktop settings... */
/* hack to get around my stupid cross-gcc headers */
#define FREEGLUT_ENUM_CURRENT_SETTINGS -1
EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS,
&fgDisplay.pDisplay.DisplayMode );
/* Make sure we will be restoring all settings needed */
fgDisplay.pDisplay.DisplayMode.dmFields |=
DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
}
/*
* Restores the previously remembered visual settings
*/
void fgPlatformRestoreState( void )
{
/* Restore the previously remembered desktop display settings */
ChangeDisplaySettingsEx( fgDisplay.pDisplay.DisplayName,&fgDisplay.pDisplay.DisplayMode, 0,0,0 );
}
/*
* Changes the current display mode to match user's settings
*/
GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest )
{ {
GLboolean success = GL_FALSE; GLboolean success = GL_FALSE;
DEVMODE devMode; DEVMODE devModeCurrent;
char *fggmstr = NULL; char *fggmstr = NULL;
char displayMode[300]; char displayMode[300];
success = GL_FALSE; /* Get current display mode */
EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devModeCurrent );
EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, -1, &devMode ); /* Now see if requested matches current mode, then we're done
devMode.dmFields = 0; * There's only four fields we touch:
* - dmPelsWidth
if (fgState.GameModeSize.X!=-1) * - dmPelsHeight
* - dmBitsPerPel
* - dmDisplayFrequency
*/
if (devModeCurrent.dmPelsWidth ==devModeRequested->dmPelsWidth &&
devModeCurrent.dmPelsHeight ==devModeRequested->dmPelsHeight &&
devModeCurrent.dmBitsPerPel ==devModeRequested->dmBitsPerPel &&
devModeCurrent.dmDisplayFrequency==devModeRequested->dmDisplayFrequency)
{ {
devMode.dmPelsWidth = fgState.GameModeSize.X; if (!haveToTest)
devMode.dmFields |= DM_PELSWIDTH;
}
if (fgState.GameModeSize.Y!=-1)
{ {
devMode.dmPelsHeight = fgState.GameModeSize.Y; /* update vars in case if actual switch was requested */
devMode.dmFields |= DM_PELSHEIGHT; EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devModeCurrent );
} fgState.GameModeSize.X = devModeCurrent.dmPelsWidth;
if (fgState.GameModeDepth!=-1) fgState.GameModeSize.Y = devModeCurrent.dmPelsHeight;
{ fgState.GameModeDepth = devModeCurrent.dmBitsPerPel;
devMode.dmBitsPerPel = fgState.GameModeDepth; fgState.GameModeRefresh = devModeCurrent.dmDisplayFrequency;
devMode.dmFields |= DM_BITSPERPEL;
}
if (fgState.GameModeRefresh!=-1)
{
devMode.dmDisplayFrequency = fgState.GameModeRefresh;
devMode.dmFields |= DM_DISPLAYFREQUENCY;
} }
switch ( ChangeDisplaySettingsEx(fgDisplay.pDisplay.DisplayName, &devMode, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) ) /* We're done */
return GL_TRUE;
}
/* Ok, we do have a mode switch to perform/test */
switch ( ChangeDisplaySettingsEx(fgDisplay.pDisplay.DisplayName, devModeRequested, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) )
{ {
case DISP_CHANGE_SUCCESSFUL: case DISP_CHANGE_SUCCESSFUL:
success = GL_TRUE; success = GL_TRUE;
@ -104,11 +77,11 @@ GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest )
if (!haveToTest) if (!haveToTest)
{ {
/* update vars in case if windows switched to proper mode */ /* update vars in case if windows switched to proper mode */
EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode ); EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devModeCurrent );
fgState.GameModeSize.X = devMode.dmPelsWidth; fgState.GameModeSize.X = devModeCurrent.dmPelsWidth;
fgState.GameModeSize.Y = devMode.dmPelsHeight; fgState.GameModeSize.Y = devModeCurrent.dmPelsHeight;
fgState.GameModeDepth = devMode.dmBitsPerPel; fgState.GameModeDepth = devModeCurrent.dmBitsPerPel;
fgState.GameModeRefresh = devMode.dmDisplayFrequency; fgState.GameModeRefresh = devModeCurrent.dmDisplayFrequency;
} }
break; break;
case DISP_CHANGE_RESTART: case DISP_CHANGE_RESTART:
@ -134,16 +107,79 @@ GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest )
if ( !success ) if ( !success )
{ {
/* I'd rather get info whats going on in my program than wonder about */ /* I'd rather get info whats going on in my program than wonder about */
/* magic happenings behind my back, its lib for devels at last ;) */ /* what magic happens behind my back, its lib for devels after all ;) */
/* append display mode to error to make things more informative */ /* append display mode to error to make things more informative */
sprintf(displayMode,"%s Problem with requested mode: %lux%lu:%lu@%lu", fggmstr, devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmDisplayFrequency); sprintf(displayMode,"%s Problem with requested mode: %lux%lu:%lu@%lu", fggmstr, devModeRequested->dmPelsWidth, devModeRequested->dmPelsHeight, devModeRequested->dmBitsPerPel, devModeRequested->dmDisplayFrequency);
fgWarning(displayMode); fgWarning(displayMode);
} }
return success; return success;
} }
/*
* Remembers the current visual settings, so that
* we can change them and restore later...
*/
void fgPlatformRememberState( void )
{
/* Grab the current desktop settings... */
EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS,
&fgDisplay.pDisplay.DisplayMode );
/* Make sure we will be restoring all settings needed */
fgDisplay.pDisplay.DisplayMode.dmFields |=
DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
}
/*
* Restores the previously remembered visual settings
*/
void fgPlatformRestoreState( void )
{
/* Restore the previously remembered desktop display settings */
fghPlatformChangeDisplayMode(GL_FALSE,&fgDisplay.pDisplay.DisplayMode);
}
/*
* Changes the current display mode to match user's settings
*/
GLboolean fgPlatformChangeDisplayMode( GLboolean haveToTest )
{
DEVMODE devMode;
/* Get current display mode */
EnumDisplaySettings( fgDisplay.pDisplay.DisplayName, ENUM_CURRENT_SETTINGS, &devMode );
devMode.dmFields = 0;
if (fgState.GameModeSize.X!=-1)
{
devMode.dmPelsWidth = fgState.GameModeSize.X;
devMode.dmFields |= DM_PELSWIDTH;
}
if (fgState.GameModeSize.Y!=-1)
{
devMode.dmPelsHeight = fgState.GameModeSize.Y;
devMode.dmFields |= DM_PELSHEIGHT;
}
if (fgState.GameModeDepth!=-1)
{
devMode.dmBitsPerPel = fgState.GameModeDepth;
devMode.dmFields |= DM_BITSPERPEL;
}
if (fgState.GameModeRefresh!=-1)
{
devMode.dmDisplayFrequency = fgState.GameModeRefresh;
devMode.dmFields |= DM_DISPLAYFREQUENCY;
}
return fghPlatformChangeDisplayMode(haveToTest, &devMode);
}
void fgPlatformEnterGameMode( void ) void fgPlatformEnterGameMode( void )
{ {
} }