X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_init.c;h=201e936cea012fed3496a4eaec8bfdc2ff53f280;hb=a7c34bdfaa680a83bf796eac2f2da20b92f4c139;hp=20fadab91d13bfc5c452d23265439368a7e86dda;hpb=bf9b5b800e3b4f99198a978800c234b6fb5c9215;p=freeglut diff --git a/src/freeglut_init.c b/src/freeglut_init.c index 20fadab..201e936 100644 --- a/src/freeglut_init.c +++ b/src/freeglut_init.c @@ -29,19 +29,19 @@ #include "config.h" #endif -#define G_LOG_DOMAIN "freeglut-init" - #include "../include/GL/freeglut.h" #include "freeglut_internal.h" /* * TODO BEFORE THE STABLE RELEASE: * - * fgDeinitialize() -- Win32's OK, X11 needs the OS-specific deinitialization done + * fgDeinitialize() -- Win32's OK, X11 needs the OS-specific + * deinitialization done * glutInitDisplayString() -- display mode string parsing * - * Wouldn't it be cool to use gettext() for error messages? I just love bash saying - * "nie znaleziono pliku" instead of "file not found" :) Is gettext easily portable? + * Wouldn't it be cool to use gettext() for error messages? I just love + * bash saying "nie znaleziono pliku" instead of "file not found" :) + * Is gettext easily portable? */ /* -- GLOBAL VARIABLES ----------------------------------------------------- */ @@ -102,7 +102,7 @@ void fgInitialize( const char* displayName ) if( !glXQueryExtension( fgDisplay.Display, NULL, NULL ) ) fgError( "OpenGL GLX extension not supported by display '%s'", - XDisplayName( displayName ) ); + XDisplayName( displayName ) ); fgDisplay.Screen = DefaultScreen( fgDisplay.Display ); fgDisplay.RootWindow = RootWindow( @@ -124,8 +124,8 @@ void fgInitialize( const char* displayName ) fgDisplay.Screen ); fgDisplay.ScreenHeightMM = DisplayHeightMM( - fgDisplay.Display, - fgDisplay.Screen + fgDisplay.Display, + fgDisplay.Screen ); fgDisplay.Connection = ConnectionNumber( fgDisplay.Display ); @@ -209,36 +209,36 @@ void fgDeinitialize( void ) if( !fgState.Time.Set ) { fgWarning( "fgDeinitialize(): fgState.Timer is null => " - "no valid initialization has been performed" ); + "no valid initialization has been performed" ); return; } /* * If there was a menu created, destroy the rendering context */ - if ( fgStructure.MenuContext ) + if( fgStructure.MenuContext ) { - free ( fgStructure.MenuContext ) ; - fgStructure.MenuContext = NULL ; + free( fgStructure.MenuContext ); + fgStructure.MenuContext = NULL; } fgDestroyStructure(); - while ( (timer = (SFG_Timer *)fgState.Timers.First) != NULL ) + while( timer = (SFG_Timer *)fgState.Timers.First ) { - fgListRemove ( &fgState.Timers, &timer->Node ) ; - free ( timer ) ; + fgListRemove ( &fgState.Timers, &timer->Node ); + free( timer ); } - fgJoystickClose(); + fgJoystickClose( ); - fgState.Position.X = -1 ; - fgState.Position.Y = -1 ; - fgState.Position.Use = FALSE ; + fgState.Position.X = -1; + fgState.Position.Y = -1; + fgState.Position.Use = FALSE; - fgState.Size.X = 300 ; - fgState.Size.Y = 300 ; - fgState.Size.Use = TRUE ; + fgState.Size.X = 300; + fgState.Size.Y = 300; + fgState.Size.Use = TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; @@ -258,26 +258,35 @@ void fgDeinitialize( void ) fgState.GameModeDepth = 16; fgState.GameModeRefresh = 72; - fgState.Time.Set = FALSE ; + fgState.Time.Set = FALSE; - fgState.Timers.First = fgState.Timers.Last = NULL ; - fgState.IdleCallback = NULL ; - fgState.MenuStateCallback = (FGCBmenuState)NULL ; - fgState.MenuStatusCallback = (FGCBmenuStatus)NULL ; + fgState.Timers.First = fgState.Timers.Last = NULL; + fgState.IdleCallback = NULL; + fgState.MenuStateCallback = (FGCBMenuState)NULL; + fgState.MenuStatusCallback = (FGCBMenuStatus)NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; fgState.FPSInterval = 0; + if( fgState.ProgramName ) + { + free( fgState.ProgramName ); + fgState.ProgramName = NULL; + } + + #if TARGET_HOST_UNIX_X11 /* - * Make sure all X-client data we have created will be destroyed on display closing + * Make sure all X-client data we have created will be destroyed on + * display closing */ XSetCloseDownMode( fgDisplay.Display, DestroyAll ); /* - * Close the display connection, destroying all windows we have created so far + * Close the display connection, destroying all windows we have + * created so far */ XCloseDisplay( fgDisplay.Display ); @@ -297,14 +306,14 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) int i, j, argc = *pargc; if (pargc && *pargc && argv && *argv && **argv) - fgState.ProgramName = strdup (*argv); + fgState.ProgramName = strdup (*argv); else - fgState.ProgramName = strdup (""); + fgState.ProgramName = strdup (""); if (!fgState.ProgramName) - fgError ("Could not allocate space for the program's name."); + fgError ("Could not allocate space for the program's name."); if( fgState.Time.Set ) - fgError( "illegal glutInit() reinitialization attemp" ); + fgError( "illegal glutInit() reinitialization attemp" ); fgCreateStructure(); @@ -317,23 +326,23 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) /* check if GLUT_FPS env var is set */ { - const char *fps = getenv ( "GLUT_FPS" ); - if ( fps ) - { - sscanf ( fps, "%d", &fgState.FPSInterval ) ; - if ( fgState.FPSInterval <= 0 ) - fgState.FPSInterval = 5000 ; /* 5000 milliseconds */ - } + const char *fps = getenv ( "GLUT_FPS" ); + if( fps ) + { + sscanf( fps, "%d", &fgState.FPSInterval ); + if( fgState.FPSInterval <= 0 ) + fgState.FPSInterval = 5000; /* 5000 milliseconds */ + } } #if TARGET_HOST_WIN32 - if ( !getenv ( "DISPLAY" ) ) - displayName = strdup ( "" ) ; + if( !getenv( "DISPLAY" ) ) + displayName = strdup( "" ); else #endif - displayName = strdup( getenv( "DISPLAY" ) ); - if (!displayName) - fgError ("Could not allocate space for display name."); + displayName = strdup( getenv( "DISPLAY" ) ); + if( !displayName ) + fgError ("Could not allocate space for display name."); for( i=1; i= argc ) + if ( ++i >= argc ) fgError( "-geometry parameter must be followed by window " - "geometry settings" ); - result = sscanf ( argv[i], "%dx%d+%d+%d", &x, &y, &w, &h ); + "geometry settings" ); + result = sscanf ( argv[i], "%dx%d+%d+%d", &x, &y, &w, &h ); - if ( result > 3 ) - fgState.Size.Y = h; - if ( result > 2 ) - fgState.Size.X = w; + if ( result > 3 ) + fgState.Size.Y = h; + if ( result > 2 ) + fgState.Size.X = w; - if( result > 1 ) + if( result > 1 ) { - if( y < 0 ) - fgState.Position.Y = - fgDisplay.ScreenHeight + y - fgState.Size.Y; - else - fgState.Position.Y = y; - } - - if( result > 0 ) + if( y < 0 ) + fgState.Position.Y = + fgDisplay.ScreenHeight + y - fgState.Size.Y; + else + fgState.Position.Y = y; + } + + if( result > 0 ) { - if( x < 0 ) - fgState.Position.X = - fgDisplay.ScreenWidth + x - fgState.Size.X; - else - fgState.Position.X = x; - } - - argv[ i - 1 ] = NULL; - argv[ i ] = NULL; - (*pargc) -= 2; + if( x < 0 ) + fgState.Position.X = + fgDisplay.ScreenWidth + x - fgState.Size.X; + else + fgState.Position.X = x; + } + + argv[ i - 1 ] = NULL; + argv[ i ] = NULL; + (*pargc) -= 2; } else if( strcmp( argv[ i ], "-direct" ) == 0) { if( fgState.TryDirectContext == FALSE ) fgError( "parameters ambiguity, -direct and -indirect " - "cannot be both specified" ); + "cannot be both specified" ); fgState.ForceDirectContext = TRUE; argv[ i ] = NULL; @@ -404,7 +413,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) { if( fgState.ForceDirectContext == TRUE ) fgError( "parameters ambiguity, -direct and -indirect " - "cannot be both specified" ); + "cannot be both specified" ); fgState.TryDirectContext = FALSE; argv[ i ] = NULL; @@ -436,13 +445,13 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) j = 2 ; for( i = 1; i < *pargc; i++, j++ ) { - if( argv[ i ] == NULL ) + if( argv[ i ] == NULL ) { - /* Guaranteed to end because there are "*pargc" arguments left */ - while ( argv[j] == NULL ) - j++; - argv[i] = argv[j] ; - } + /* Guaranteed to end because there are "*pargc" arguments left */ + while ( argv[j] == NULL ) + j++; + argv[i] = argv[j] ; + } } /* @@ -468,7 +477,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) fgState.Size.Use = FALSE; if( displayName ) - free( displayName ); + free( displayName ); } /* @@ -478,7 +487,6 @@ void FGAPIENTRY glutInitWindowPosition( int x, int y ) { if( (x >= 0) && (y >= 0) ) { - fgState.Position.X = x; fgState.Position.Y = y; fgState.Position.Use = TRUE; @@ -576,7 +584,7 @@ static GScannerConfig fgInitDisplayStringScannerConfig = G_CSET_a_2_z "_" G_CSET_A_2_Z - ) /* cset_identifier_first */, + ) /* cset_identifier_first */, ( G_CSET_a_2_z "_0123456789" @@ -584,29 +592,29 @@ static GScannerConfig fgInitDisplayStringScannerConfig = G_CSET_LATINS G_CSET_LATINC "<>!=~" - ) /* cset_identifier_nth */, - ( "#\n" ) /* cpair_comment_single */, - FALSE /* case_sensitive */, - TRUE /* skip_comment_multi */, - TRUE /* skip_comment_single */, - TRUE /* scan_comment_multi */, - TRUE /* scan_identifier */, - FALSE /* scan_identifier_1char */, - FALSE /* scan_identifier_NULL */, - TRUE /* scan_symbols */, - FALSE /* scan_binary */, - TRUE /* scan_octal */, - TRUE /* scan_float */, - TRUE /* scan_hex */, - FALSE /* scan_hex_dollar */, - TRUE /* scan_string_sq */, - TRUE /* scan_string_dq */, - TRUE /* numbers_2_int */, - FALSE /* int_2_float */, - FALSE /* identifier_2_string */, - TRUE /* char_2_token */, - FALSE /* symbol_2_token */, - FALSE /* scope_0_fallback */, + ) /* cset_identifier_nth */, + ( "#\n" ) /* cpair_comment_single */, + FALSE /* case_sensitive */, + TRUE /* skip_comment_multi */, + TRUE /* skip_comment_single */, + TRUE /* scan_comment_multi */, + TRUE /* scan_identifier */, + FALSE /* scan_identifier_1char */, + FALSE /* scan_identifier_NULL */, + TRUE /* scan_symbols */, + FALSE /* scan_binary */, + TRUE /* scan_octal */, + TRUE /* scan_float */, + TRUE /* scan_hex */, + FALSE /* scan_hex_dollar */, + TRUE /* scan_string_sq */, + TRUE /* scan_string_dq */, + TRUE /* numbers_2_int */, + FALSE /* int_2_float */, + FALSE /* identifier_2_string */, + TRUE /* char_2_token */, + FALSE /* symbol_2_token */, + FALSE /* scope_0_fallback */, }; /* @@ -723,9 +731,9 @@ void FGAPIENTRY glutInitDisplayString( char* displayMode ) if( comparison != FG_NONE && i < (gint) strlen( scanner->value.v_identifier ) ) { valueString = strdup( scanner->value.v_identifier + i ); - if (!valueString) - fgError ("Could not allocate an internal string."); - } + if (!valueString) + fgError ("Could not allocate an internal string."); + } /* * If there was a value string, convert it to integer...