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:
parent
3dda2ed20b
commit
51ce35c19d
@ -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 ) )
|
|
||||||
{
|
|
||||||
mode = displayModes;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
displayModes++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( mode == 0xffffffff )
|
// update vars in case if windows switched to proper mode
|
||||||
{
|
EnumDisplaySettings( NULL, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode );
|
||||||
/* then try without Display Frequency */
|
|
||||||
displayModes = 0;
|
|
||||||
|
|
||||||
/* Enumerate the available display modes */
|
|
||||||
while( EnumDisplaySettings( NULL, displayModes, &devMode ) )
|
|
||||||
{
|
|
||||||
/* then try without Display Frequency */
|
|
||||||
if( fghCheckDisplayMode( devMode.dmPelsWidth,
|
|
||||||
devMode.dmPelsHeight,
|
|
||||||
devMode.dmBitsPerPel,
|
|
||||||
fgState.GameModeRefresh ) )
|
|
||||||
{
|
|
||||||
mode = displayModes;
|
|
||||||
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.X = devMode.dmPelsWidth;
|
||||||
fgState.GameModeSize.Y = devMode.dmPelsHeight;
|
fgState.GameModeSize.Y = devMode.dmPelsHeight;
|
||||||
fgState.GameModeDepth = devMode.dmBitsPerPel;
|
fgState.GameModeDepth = devMode.dmBitsPerPel;
|
||||||
fgState.GameModeRefresh = devMode.dmDisplayFrequency;
|
fgState.GameModeRefresh = devMode.dmDisplayFrequency;
|
||||||
}
|
break;
|
||||||
|
case DISP_CHANGE_RESTART:
|
||||||
|
strcpy(fggmstr,"The computer must be restarted for the graphics mode to work.");
|
||||||
|
break;
|
||||||
|
case DISP_CHANGE_BADFLAGS:
|
||||||
|
strcpy(fggmstr,"An invalid set of flags was passed in.");
|
||||||
|
break;
|
||||||
|
case DISP_CHANGE_BADPARAM:
|
||||||
|
strcpy(fggmstr,"An invalid parameter was passed in. This can include an invalid flag or combination of flags.");
|
||||||
|
break;
|
||||||
|
case DISP_CHANGE_FAILED:
|
||||||
|
strcpy(fggmstr,"The display driver failed the specified graphics mode.");
|
||||||
|
break;
|
||||||
|
case DISP_CHANGE_BADMODE:
|
||||||
|
strcpy(fggmstr,"The graphics mode is not supported.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
strcpy(fggmstr,"Unknown error in graphics mode???"); /* dunno if it is possible,MSDN does not mention any other error */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
Reference in New Issue
Block a user