Misiek\'s changes to fix Game Mode--getting display settings under Windows

and setting the window size correctly on all operating systems.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@612 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
fayjf 2005-05-17 16:50:30 +00:00
parent 3dda2ed20b
commit 51ce35c19d

View File

@ -302,72 +302,55 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest )
#elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
unsigned int displayModes = 0, mode = 0xffffffff;
/* HDC desktopDC; */
DEVMODE devMode; DEVMODE devMode;
char fggmstr[255]="";
/* success = GL_FALSE;
* Enumerate the available display modes
* Try to get a complete match EnumDisplaySettings( NULL, -1, &devMode );
*/ devMode.dmFields |= DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
while( EnumDisplaySettings( NULL, displayModes, &devMode ) )
devMode.dmPelsWidth = fgState.GameModeSize.X;
devMode.dmPelsHeight = fgState.GameModeSize.Y;
devMode.dmBitsPerPel = fgState.GameModeDepth;
devMode.dmDisplayFrequency = fgState.GameModeRefresh;
devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
switch ( ChangeDisplaySettingsEx(NULL, &devMode, NULL, haveToTest ? CDS_TEST : CDS_FULLSCREEN , NULL) )
{ {
/* Does the enumerated display mode match the user's preferences? */ case DISP_CHANGE_SUCCESSFUL:
if( fghCheckDisplayMode( devMode.dmPelsWidth, devMode.dmPelsHeight, success = GL_TRUE;
devMode.dmBitsPerPel,
devMode.dmDisplayFrequency ) ) // update vars in case if windows switched to proper mode
{ EnumDisplaySettings( NULL, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode );
mode = displayModes; fgState.GameModeSize.X = devMode.dmPelsWidth;
break; fgState.GameModeSize.Y = devMode.dmPelsHeight;
} fgState.GameModeDepth = devMode.dmBitsPerPel;
displayModes++; fgState.GameModeRefresh = devMode.dmDisplayFrequency;
} break;
case DISP_CHANGE_RESTART:
if( mode == 0xffffffff ) strcpy(fggmstr,"The computer must be restarted for the graphics mode to work.");
{ break;
/* then try without Display Frequency */ case DISP_CHANGE_BADFLAGS:
displayModes = 0; strcpy(fggmstr,"An invalid set of flags was passed in.");
break;
/* Enumerate the available display modes */ case DISP_CHANGE_BADPARAM:
while( EnumDisplaySettings( NULL, displayModes, &devMode ) ) strcpy(fggmstr,"An invalid parameter was passed in. This can include an invalid flag or combination of flags.");
{ break;
/* then try without Display Frequency */ case DISP_CHANGE_FAILED:
if( fghCheckDisplayMode( devMode.dmPelsWidth, strcpy(fggmstr,"The display driver failed the specified graphics mode.");
devMode.dmPelsHeight, break;
devMode.dmBitsPerPel, case DISP_CHANGE_BADMODE:
fgState.GameModeRefresh ) ) strcpy(fggmstr,"The graphics mode is not supported.");
{ break;
mode = displayModes; default:
break; strcpy(fggmstr,"Unknown error in graphics mode???"); /* dunno if it is possible,MSDN does not mention any other error */
} break;
displayModes++;
}
}
/* Did we find a matching display mode? */
if( mode != 0xffffffff )
{
int retVal = DISP_CHANGE_SUCCESSFUL;
/* Mark the values we want to modify in the display change call */
devMode.dmFields |=
DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
retVal = ChangeDisplaySettings( &devMode, haveToTest ? CDS_TEST : 0 );
/* I don't know if it's really needed, but looks nice: */
success = (retVal == DISP_CHANGE_SUCCESSFUL) ||
(retVal == DISP_CHANGE_NOTUPDATED);
if( !haveToTest && success )
{
fgState.GameModeSize.X = devMode.dmPelsWidth;
fgState.GameModeSize.Y = devMode.dmPelsHeight;
fgState.GameModeDepth = devMode.dmBitsPerPel;
fgState.GameModeRefresh = devMode.dmDisplayFrequency;
}
} }
if ( !success )
fgWarning(fggmstr); /* 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 ;) */
#endif #endif
return success; return success;
@ -434,6 +417,9 @@ int FGAPIENTRY glutEnterGameMode( void )
fgState.GameModeSize.X, fgState.GameModeSize.Y, GL_TRUE, GL_FALSE fgState.GameModeSize.X, fgState.GameModeSize.Y, GL_TRUE, GL_FALSE
); );
fgStructure.GameMode->State.Width = fgState.GameModeSize.X;
fgStructure.GameMode->State.Height = fgState.GameModeSize.Y;
fgStructure.GameMode->State.IsGameMode = GL_TRUE; fgStructure.GameMode->State.IsGameMode = GL_TRUE;
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11