Style normalization; removal of say-nothing-useful comments.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@315 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-11-07 08:46:53 +00:00
parent 5621aa7fcb
commit ca361547ec

View File

@ -53,7 +53,8 @@ void fghRememberState( void )
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/* /*
* This highly depends on the XFree86 extensions, not approved as X Consortium standards * This highly depends on the XFree86 extensions,
* not approved as X Consortium standards
*/ */
# ifdef X_XF86VidModeGetModeLine # ifdef X_XF86VidModeGetModeLine
@ -106,7 +107,7 @@ void fghRememberState( void )
#elif TARGET_HOST_WIN32 #elif TARGET_HOST_WIN32
/* DEVMODE devMode; */ /* DEVMODE devMode; */
/* /*
* Grab the current desktop settings... * Grab the current desktop settings...
*/ */
@ -114,12 +115,14 @@ void fghRememberState( void )
/* hack to get around my stupid cross-gcc headers */ /* hack to get around my stupid cross-gcc headers */
#define FREEGLUT_ENUM_CURRENT_SETTINGS -1 #define FREEGLUT_ENUM_CURRENT_SETTINGS -1
EnumDisplaySettings( NULL, FREEGLUT_ENUM_CURRENT_SETTINGS, &fgDisplay.DisplayMode ); EnumDisplaySettings( NULL, FREEGLUT_ENUM_CURRENT_SETTINGS,
&fgDisplay.DisplayMode );
/* /*
* Make sure we will be restoring all settings needed * Make sure we will be restoring all settings needed
*/ */
fgDisplay.DisplayMode.dmFields |= DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; fgDisplay.DisplayMode.dmFields |=
DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
#endif #endif
} }
@ -141,7 +144,8 @@ void fghRestoreState( void )
); );
/* /*
* This highly depends on the XFree86 extensions, not approved as X Consortium standards * This highly depends on the XFree86 extensions,
* not approved as X Consortium standards
*/ */
if (fgDisplay.DisplayModeValid) if (fgDisplay.DisplayModeValid)
@ -149,9 +153,6 @@ void fghRestoreState( void )
XF86VidModeModeInfo** displayModes; XF86VidModeModeInfo** displayModes;
int i, displayModesCount; int i, displayModesCount;
/*
* Query for all the display available...
*/
XF86VidModeGetAllModeLines( XF86VidModeGetAllModeLines(
fgDisplay.Display, fgDisplay.Display,
fgDisplay.Screen, fgDisplay.Screen,
@ -160,26 +161,20 @@ void fghRestoreState( void )
); );
/* /*
* Check every of the modes looking for one that matches our demands * Check every of the modes looking for one that matches our demands.
* If we find one, switch to it and restore the remembered viewport.
*/ */
for( i=0; i<displayModesCount; i++ ) for( i = 0; i < displayModesCount; i++ )
{ {
if( displayModes[ i ]->hdisplay == fgDisplay.DisplayMode.hdisplay && if(displayModes[ i ]->hdisplay == fgDisplay.DisplayMode.hdisplay &&
displayModes[ i ]->vdisplay == fgDisplay.DisplayMode.vdisplay && displayModes[ i ]->vdisplay == fgDisplay.DisplayMode.vdisplay &&
displayModes[ i ]->dotclock == fgDisplay.DisplayModeClock ) displayModes[ i ]->dotclock == fgDisplay.DisplayModeClock )
{ {
/*
* OK, this is the display mode we have been looking for...
*/
XF86VidModeSwitchToMode( XF86VidModeSwitchToMode(
fgDisplay.Display, fgDisplay.Display,
fgDisplay.Screen, fgDisplay.Screen,
displayModes[ i ] displayModes[ i ]
); );
/*
* Now we can restore the remembered ViewPort:
*/
XF86VidModeSetViewPort( XF86VidModeSetViewPort(
fgDisplay.Display, fgDisplay.Display,
fgDisplay.Screen, fgDisplay.Screen,
@ -187,12 +182,12 @@ void fghRestoreState( void )
fgDisplay.DisplayViewPortY fgDisplay.DisplayViewPortY
); );
/* /*
* For the case this would be the last X11 call the application * For the case this would be the last X11 call the application
* calls exit() we've to flush the X11 output queue to have the * calls exit() we've to flush the X11 output queue to have the
* commands sent to the X server before the application exists. * commands sent to the X server before the application exits.
*/ */
XFlush(fgDisplay.Display); XFlush( fgDisplay.Display );
return; return;
} }
@ -221,8 +216,10 @@ GLboolean fghCheckDisplayMode( int width, int height, int depth, int refresh )
/* /*
* The desired values should be stored in fgState structure... * The desired values should be stored in fgState structure...
*/ */
return( (width == fgState.GameModeSize.X) && (height == fgState.GameModeSize.Y) && return( (width == fgState.GameModeSize.X) &&
(depth == fgState.GameModeDepth) && (refresh == fgState.GameModeRefresh) ); (height == fgState.GameModeSize.Y) &&
(depth == fgState.GameModeDepth) &&
(refresh == fgState.GameModeRefresh) );
} }
/* /*
@ -233,7 +230,8 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/* /*
* This highly depends on the XFree86 extensions, not approved as X Consortium standards * This highly depends on the XFree86 extensions,
* not approved as X Consortium standards
*/ */
# ifdef X_XF86VidModeGetAllModeLines # ifdef X_XF86VidModeGetAllModeLines
@ -246,9 +244,6 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
XF86VidModeModeInfo** displayModes; XF86VidModeModeInfo** displayModes;
int i, displayModesCount; int i, displayModesCount;
/*
* Query for all the display available...
*/
XF86VidModeGetAllModeLines( XF86VidModeGetAllModeLines(
fgDisplay.Display, fgDisplay.Display,
fgDisplay.Screen, fgDisplay.Screen,
@ -259,13 +254,15 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
/* /*
* Check every of the modes looking for one that matches our demands * Check every of the modes looking for one that matches our demands
*/ */
for( i=0; i<displayModesCount; i++ ) for( i = 0; i < displayModesCount; i++ )
{ {
if( fghCheckDisplayMode( displayModes[ i ]->hdisplay, displayModes[ i ]->vdisplay, if( fghCheckDisplayMode( displayModes[ i ]->hdisplay,
fgState.GameModeDepth, fgState.GameModeRefresh ) ) displayModes[ i ]->vdisplay,
fgState.GameModeDepth,
fgState.GameModeRefresh ) )
{ {
if( haveToTest ) if( haveToTest )
return( TRUE ); return TRUE;
/* /*
* OKi, this is the display mode we have been looking for... * OKi, this is the display mode we have been looking for...
*/ */
@ -274,10 +271,7 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
fgDisplay.Screen, fgDisplay.Screen,
displayModes[ i ] displayModes[ i ]
); );
/* return TRUE;
* Return successfull...
*/
return( TRUE );
} }
} }
} }
@ -285,7 +279,7 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
/* /*
* Something must have went wrong * Something must have went wrong
*/ */
return( FALSE ); return FALSE;
# else # else
# warning fghChangeDisplayMode: missing XFree86 video mode extensions, game mode will not change screen resolution when activated # warning fghChangeDisplayMode: missing XFree86 video mode extensions, game mode will not change screen resolution when activated
@ -295,7 +289,7 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
unsigned int displayModes = 0, mode = 0xffffffff; unsigned int displayModes = 0, mode = 0xffffffff;
GLboolean success = FALSE; GLboolean success = FALSE;
/* HDC desktopDC; */ /* HDC desktopDC; */
DEVMODE devMode; DEVMODE devMode;
/* /*
@ -308,48 +302,36 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
* Does the enumerated display mode match the user's preferences? * Does the enumerated display mode match the user's preferences?
*/ */
if( fghCheckDisplayMode( devMode.dmPelsWidth, devMode.dmPelsHeight, if( fghCheckDisplayMode( devMode.dmPelsWidth, devMode.dmPelsHeight,
devMode.dmBitsPerPel, devMode.dmDisplayFrequency ) ) devMode.dmBitsPerPel,
devMode.dmDisplayFrequency ) )
{ {
/*
* OKi, we've found a matching display mode, remember its number and break
*/
mode = displayModes; mode = displayModes;
break; break;
} }
/*
* Switch to the next display mode, if any
*/
displayModes++; displayModes++;
} }
if ( mode == 0xffffffff ) if ( mode == 0xffffffff )
{ {
/* then try without Display Frequency */
displayModes = 0;
/*
* Enumerate the available display modes
*/
while( EnumDisplaySettings( NULL, displayModes, &devMode ) == TRUE )
{
/* then try without Display Frequency */ /* then try without Display Frequency */
displayModes = 0;
if( fghCheckDisplayMode( devMode.dmPelsWidth, devMode.dmPelsHeight,
devMode.dmBitsPerPel, fgState.GameModeRefresh))
{
/*
* OKi, we've found a matching display mode, remember its number and break
*/
mode = displayModes;
break;
}
/* /*
* Switch to the next display mode, if any * Enumerate the available display modes
*/ */
displayModes++; while( EnumDisplaySettings( NULL, displayModes, &devMode ) == TRUE )
} {
/* then try without Display Frequency */
if( fghCheckDisplayMode( devMode.dmPelsWidth,
devMode.dmPelsHeight,
devMode.dmBitsPerPel,
fgState.GameModeRefresh ) )
{
mode = displayModes;
break;
}
displayModes++;
}
} }
/* /*
@ -362,21 +344,17 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
/* /*
* Mark the values we want to modify in the display change call * Mark the values we want to modify in the display change call
*/ */
devMode.dmFields |= DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; devMode.dmFields |=
DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
/*
* Change the current display mode (possibly in test mode only)
*/
retVal = ChangeDisplaySettings( &devMode, haveToTest ? CDS_TEST : 0 ); retVal = ChangeDisplaySettings( &devMode, haveToTest ? CDS_TEST : 0 );
/* /*
* I don't know if it's really needed, but looks nice: * I don't know if it's really needed, but looks nice:
*/ */
success = (retVal == DISP_CHANGE_SUCCESSFUL) || (retVal == DISP_CHANGE_NOTUPDATED); success = (retVal == DISP_CHANGE_SUCCESSFUL) ||
(retVal == DISP_CHANGE_NOTUPDATED);
/*
* If it was not a test, remember the current screen settings
*/
if( !haveToTest && success ) if( !haveToTest && success )
{ {
fgState.GameModeSize.X = devMode.dmPelsWidth; fgState.GameModeSize.X = devMode.dmPelsWidth;
@ -386,10 +364,7 @@ GLboolean fghChangeDisplayMode( GLboolean haveToTest )
} }
} }
/* return success;
* Otherwise we must have failed somewhere
*/
return( success );
#endif #endif
} }
@ -410,14 +385,18 @@ void FGAPIENTRY glutGameModeString( const char* string )
* that I assumed it is: "[width]x[height]:[depth]@[refresh rate]", which * that I assumed it is: "[width]x[height]:[depth]@[refresh rate]", which
* appears in all GLUT game mode programs I have seen to date. * appears in all GLUT game mode programs I have seen to date.
*/ */
if( sscanf( string, "%ix%i:%i@%i", &width, &height, &depth, &refresh ) != 4 ) if( sscanf( string, "%ix%i:%i@%i", &width, &height, &depth, &refresh ) !=
4 )
if( sscanf( string, "%ix%i:%i", &width, &height, &depth ) != 3 ) if( sscanf( string, "%ix%i:%i", &width, &height, &depth ) != 3 )
if( sscanf( string, "%ix%i@%i", &width, &height, &refresh ) != 3 ) if( sscanf( string, "%ix%i@%i", &width, &height, &refresh ) != 3 )
if( sscanf( string, "%ix%i", &width, &height ) != 2 ) if( sscanf( string, "%ix%i", &width, &height ) != 2 )
if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 ) if( sscanf( string, ":%i@%i", &depth, &refresh ) != 2 )
if( sscanf( string, ":%i", &depth ) != 1 ) if( sscanf( string, ":%i", &depth ) != 1 )
if( sscanf( string, "@%i", &refresh ) != 1 ) if( sscanf( string, "@%i", &refresh ) != 1 )
fgWarning( "unable to parse game mode string `%s'", string ); fgWarning(
"unable to parse game mode string `%s'",
string
);
/* /*
* Hopefully it worked, and if not, we still have the default values * Hopefully it worked, and if not, we still have the default values
@ -433,50 +412,32 @@ void FGAPIENTRY glutGameModeString( const char* string )
*/ */
int FGAPIENTRY glutEnterGameMode( void ) int FGAPIENTRY glutEnterGameMode( void )
{ {
/* if( fgStructure.GameMode )
* Check if a game mode window already exists...
*/
if( fgStructure.GameMode != NULL )
{
/*
* ...if so, delete it before proceeding...
*/
fgAddToWindowDestroyList( fgStructure.GameMode, TRUE ); fgAddToWindowDestroyList( fgStructure.GameMode, TRUE );
}
else else
{ fghRememberState( );
/*
* ...otherwise remember the current resolution, etc.
*/
fghRememberState();
}
/*
* We are ready to change the current screen's resolution now
*/
if( fghChangeDisplayMode( FALSE ) == FALSE ) if( fghChangeDisplayMode( FALSE ) == FALSE )
{ {
fgWarning( "failed to change screen settings" ); fgWarning( "failed to change screen settings" );
return( FALSE ); return FALSE;
} }
/*
* Finally, have the game mode window created
*/
fgStructure.GameMode = fgCreateWindow( fgStructure.GameMode = fgCreateWindow(
NULL, "FREEGLUT", 0, 0, fgState.GameModeSize.X, fgState.GameModeSize.Y, TRUE NULL, "FREEGLUT", 0, 0,
fgState.GameModeSize.X, fgState.GameModeSize.Y, TRUE
); );
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/* Move the window up to the topleft corner */ /* Move the window up to the topleft corner */
XMoveWindow(fgDisplay.Display, fgStructure.Window->Window.Handle, 0, 0); XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, 0, 0 );
/* /*
* Sync needed to avoid a real race, the Xserver must have really created * Sync needed to avoid a real race, the Xserver must have really created
* the window before we can grab the pointer into it: * the window before we can grab the pointer into it:
*/ */
XSync(fgDisplay.Display, False); XSync( fgDisplay.Display, False );
/* Move the Pointer to the middle of the fullscreen window */ /* Move the Pointer to the middle of the fullscreen window */
XWarpPointer( XWarpPointer(
@ -496,15 +457,15 @@ int FGAPIENTRY glutEnterGameMode( void )
* (XSetInputFocus) is called with a not yet viewable window, it will exit * (XSetInputFocus) is called with a not yet viewable window, it will exit
* the application which we have to aviod, so wait until it's viewable: * the application which we have to aviod, so wait until it's viewable:
*/ */
while (GrabSuccess != XGrabPointer( while( GrabSuccess != XGrabPointer(
fgDisplay.Display, fgStructure.GameMode->Window.Handle, fgDisplay.Display, fgStructure.GameMode->Window.Handle,
TRUE, ButtonPressMask|ButtonReleaseMask|ButtonMotionMask TRUE,
|PointerMotionMask, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
GrabModeAsync, GrabModeAsync, | PointerMotionMask,
fgStructure.GameMode->Window.Handle, None, CurrentTime)) { GrabModeAsync, GrabModeAsync,
usleep (100); fgStructure.GameMode->Window.Handle, None, CurrentTime) )
} usleep( 100 );
/* /*
* Change input focus to the new window. This will exit the application * Change input focus to the new window. This will exit the application
* if the new window is not viewable yet, see the XGrabPointer loop above. * if the new window is not viewable yet, see the XGrabPointer loop above.
@ -518,19 +479,20 @@ int FGAPIENTRY glutEnterGameMode( void )
# ifdef X_XF86VidModeSetViewPort # ifdef X_XF86VidModeSetViewPort
if (fgDisplay.DisplayModeValid) { if (fgDisplay.DisplayModeValid)
{
int x, y; int x, y;
Window child; Window child;
/* /*
* Change to viewport to the window topleft edge: * Change to viewport to the window topleft edge:
*/ */
XF86VidModeSetViewPort(fgDisplay.Display, fgDisplay.Screen, 0, 0); XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 );
/* /*
* Final window repositioning: It could be avoided using an undecorated * Final window repositioning: It could be avoided using an undecorated
* window using override_redirect, but this * would possily require more * window using override_redirect, but this * would possily require
* changes and investigation. * more changes and investigation.
*/ */
/* Get the current postion of the drawable area on screen */ /* Get the current postion of the drawable area on screen */
@ -543,7 +505,8 @@ int FGAPIENTRY glutEnterGameMode( void )
); );
/* Move the decorataions out of the topleft corner of the display */ /* Move the decorataions out of the topleft corner of the display */
XMoveWindow(fgDisplay.Display, fgStructure.Window->Window.Handle, -x, -y); XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle,
-x, -y);
} }
#endif #endif
@ -561,10 +524,7 @@ int FGAPIENTRY glutEnterGameMode( void )
#endif #endif
/* return TRUE;
* Return successfull
*/
return( TRUE );
} }
/* /*
@ -572,26 +532,17 @@ int FGAPIENTRY glutEnterGameMode( void )
*/ */
void FGAPIENTRY glutLeaveGameMode( void ) void FGAPIENTRY glutLeaveGameMode( void )
{ {
freeglut_return_if_fail( fgStructure.GameMode != NULL ); freeglut_return_if_fail( fgStructure.GameMode );
/*
* First of all, have the game mode window destroyed
*/
fgAddToWindowDestroyList( fgStructure.GameMode, TRUE ); fgAddToWindowDestroyList( fgStructure.GameMode, TRUE );
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/*
* Ungrab the mouse and keyboard
*/
XUngrabPointer( fgDisplay.Display, CurrentTime ); XUngrabPointer( fgDisplay.Display, CurrentTime );
XUngrabKeyboard( fgDisplay.Display, CurrentTime ); XUngrabKeyboard( fgDisplay.Display, CurrentTime );
#endif #endif
/*
* Then, have the desktop visual settings restored
*/
fghRestoreState(); fghRestoreState();
} }
@ -600,59 +551,34 @@ void FGAPIENTRY glutLeaveGameMode( void )
*/ */
int FGAPIENTRY glutGameModeGet( GLenum eWhat ) int FGAPIENTRY glutGameModeGet( GLenum eWhat )
{ {
/*
* See why are we bothered
*/
switch( eWhat ) switch( eWhat )
{ {
case GLUT_GAME_MODE_ACTIVE: case GLUT_GAME_MODE_ACTIVE:
/* return !!fgStructure.GameMode;
* Check if the game mode is currently active
*/
return( fgStructure.GameMode != NULL );
case GLUT_GAME_MODE_POSSIBLE: case GLUT_GAME_MODE_POSSIBLE:
/* return fghChangeDisplayMode( TRUE );
* Check if the current game mode settings are valid
*/
return( fghChangeDisplayMode( TRUE ) );
case GLUT_GAME_MODE_WIDTH: case GLUT_GAME_MODE_WIDTH:
/* return fgState.GameModeSize.X;
* The game mode screen width
*/
return( fgState.GameModeSize.X );
case GLUT_GAME_MODE_HEIGHT: case GLUT_GAME_MODE_HEIGHT:
/* return fgState.GameModeSize.Y;
* The game mode screen height
*/
return( fgState.GameModeSize.Y );
case GLUT_GAME_MODE_PIXEL_DEPTH: case GLUT_GAME_MODE_PIXEL_DEPTH:
/* return fgState.GameModeDepth;
* The game mode pixel depth
*/
return( fgState.GameModeDepth );
case GLUT_GAME_MODE_REFRESH_RATE: case GLUT_GAME_MODE_REFRESH_RATE:
/* return fgState.GameModeRefresh;
* The game mode refresh rate
*/
return( fgState.GameModeRefresh );
case GLUT_GAME_MODE_DISPLAY_CHANGED: case GLUT_GAME_MODE_DISPLAY_CHANGED:
/* /*
* This is true if the game mode has been activated successfully.. * This is true if the game mode has been activated successfully..
*/ */
return( fgStructure.GameMode != NULL ); return !!fgStructure.GameMode;
} }
return( -1 ); return -1;
} }
/*** END OF FILE ***/ /*** END OF FILE ***/