X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_init.c;h=5fabb611160817af7c06fe3283569ef862131bee;hb=074fe7a4ceb20811af83f735d5db74d69d11442c;hp=201e936cea012fed3496a4eaec8bfdc2ff53f280;hpb=5d724da03c1b5988304888c17c5eba8a40c0a529;p=freeglut diff --git a/src/freeglut_init.c b/src/freeglut_init.c index 201e936..5fabb61 100644 --- a/src/freeglut_init.c +++ b/src/freeglut_init.c @@ -55,35 +55,36 @@ SFG_Display fgDisplay; /* * The settings for the current freeglut session */ -SFG_State fgState = { { -1, -1, FALSE }, /* Position */ - { 300, 300, TRUE }, /* Size */ +SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */ + { 300, 300, GL_TRUE }, /* Size */ GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */ - FALSE, /* ForceDirectContext */ - TRUE, /* TryDirectContext */ - FALSE, /* ForceIconic */ - FALSE, /* UseCurrentContext */ - FALSE, /* GLDebugSwitch */ - FALSE, /* XSyncSwitch */ - TRUE, /* IgnoreKeyRepeat */ - 0, /* FPSInterval */ - 0, /* SwapCount */ - 0, /* SwapTime */ + GL_FALSE, /* Initalized */ + GL_FALSE, /* ForceDirectContext */ + GL_TRUE, /* TryDirectContext */ + GL_FALSE, /* ForceIconic */ + GL_FALSE, /* UseCurrentContext */ + GL_FALSE, /* GLDebugSwitch */ + GL_FALSE, /* XSyncSwitch */ + GL_TRUE, /* IgnoreKeyRepeat */ + 0, /* FPSInterval */ + 0, /* SwapCount */ + 0, /* SwapTime */ #if TARGET_HOST_WIN32 - { 0, FALSE }, /* Time */ + { 0, GL_FALSE }, /* Time */ #else - { { 0, 0 }, FALSE }, + { { 0, 0 }, GL_FALSE }, #endif - { NULL, NULL }, /* Timers */ - NULL, /* IdleCallback */ - FALSE, /* BuildingAMenu */ - 0, /* ActiveMenus */ - NULL, /* MenuStateCallback */ - NULL, /* MenuStatusCallback */ - { 640, 480, TRUE }, /* GameModeSize */ - 16, /* GameModeDepth */ - 72, /* GameModeRefresh */ - GLUT_ACTION_EXIT, /* ActionOnWindowClose */ - GLUT_EXEC_STATE_INIT /* ExecState */ + { NULL, NULL }, /* Timers */ + NULL, /* IdleCallback */ + GL_FALSE, /* BuildingAMenu */ + 0, /* ActiveMenus */ + NULL, /* MenuStateCallback */ + NULL, /* MenuStatusCallback */ + { 640, 480, GL_TRUE }, /* GameModeSize */ + 16, /* GameModeDepth */ + 72, /* GameModeRefresh */ + GLUT_ACTION_EXIT, /* ActionOnWindowClose */ + GLUT_EXEC_STATE_INIT /* ExecState */ } ; @@ -175,7 +176,7 @@ void fgInitialize( const char* displayName ) * Register the window class */ atom = RegisterClass( &wc ); - assert( atom != 0 ); + assert( atom ); } /* @@ -185,7 +186,7 @@ void fgInitialize( const char* displayName ) fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN ); { - HWND desktop = GetDesktopWindow(); + HWND desktop = GetDesktopWindow( ); HDC context = GetDC( desktop ); fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE ); @@ -197,6 +198,8 @@ void fgInitialize( const char* displayName ) #endif fgJoystickInit( 0 ); + + fgState.Initalized = GL_TRUE; } /* @@ -206,13 +209,15 @@ void fgDeinitialize( void ) { SFG_Timer *timer; - if( !fgState.Time.Set ) + if( !fgState.Initalized ) { - fgWarning( "fgDeinitialize(): fgState.Timer is null => " - "no valid initialization has been performed" ); + fgWarning( "fgDeinitialize(): " + "no valid initialization has been performed" ); return; } + fgState.Initalized = GL_FALSE; + /* * If there was a menu created, destroy the rendering context */ @@ -222,9 +227,9 @@ void fgDeinitialize( void ) fgStructure.MenuContext = NULL; } - fgDestroyStructure(); + fgDestroyStructure( ); - while( timer = (SFG_Timer *)fgState.Timers.First ) + while( timer = ( SFG_Timer * )fgState.Timers.First ) { fgListRemove ( &fgState.Timers, &timer->Node ); free( timer ); @@ -234,36 +239,36 @@ void fgDeinitialize( void ) fgState.Position.X = -1; fgState.Position.Y = -1; - fgState.Position.Use = FALSE; + fgState.Position.Use = GL_FALSE; fgState.Size.X = 300; fgState.Size.Y = 300; - fgState.Size.Use = TRUE; + fgState.Size.Use = GL_TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; - fgState.ForceDirectContext = FALSE; - fgState.TryDirectContext = TRUE; - fgState.ForceIconic = FALSE; - fgState.UseCurrentContext = FALSE; - fgState.GLDebugSwitch = FALSE; - fgState.XSyncSwitch = FALSE; + fgState.ForceDirectContext = GL_FALSE; + fgState.TryDirectContext = GL_TRUE; + fgState.ForceIconic = GL_FALSE; + fgState.UseCurrentContext = GL_FALSE; + fgState.GLDebugSwitch = GL_FALSE; + fgState.XSyncSwitch = GL_FALSE; fgState.ActionOnWindowClose = GLUT_ACTION_EXIT ; fgState.ExecState = GLUT_EXEC_STATE_INIT ; - fgState.IgnoreKeyRepeat = TRUE; + fgState.IgnoreKeyRepeat = GL_TRUE; fgState.GameModeSize.X = 640; fgState.GameModeSize.Y = 480; fgState.GameModeDepth = 16; fgState.GameModeRefresh = 72; - fgState.Time.Set = FALSE; + fgState.Time.Set = GL_FALSE; fgState.Timers.First = fgState.Timers.Last = NULL; fgState.IdleCallback = NULL; - fgState.MenuStateCallback = (FGCBMenuState)NULL; - fgState.MenuStatusCallback = (FGCBMenuStatus)NULL; + fgState.MenuStateCallback = ( FGCBMenuState )NULL; + fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; @@ -309,24 +314,19 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) fgState.ProgramName = strdup (*argv); else fgState.ProgramName = strdup (""); - if (!fgState.ProgramName) + if( !fgState.ProgramName ) fgError ("Could not allocate space for the program's name."); - if( fgState.Time.Set ) + if( fgState.Initalized ) fgError( "illegal glutInit() reinitialization attemp" ); - fgCreateStructure(); + fgCreateStructure( ); -#if TARGET_HOST_UNIX_X11 - gettimeofday(&fgState.Time.Value, NULL); -#elif TARGET_HOST_WIN32 - fgState.Time.Value = timeGetTime(); -#endif - fgState.Time.Set = TRUE; + fgElapsedTime( ); /* check if GLUT_FPS env var is set */ { - const char *fps = getenv ( "GLUT_FPS" ); + const char *fps = getenv( "GLUT_FPS" ); if( fps ) { sscanf( fps, "%d", &fgState.FPSInterval ); @@ -342,9 +342,9 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) #endif displayName = strdup( getenv( "DISPLAY" ) ); if( !displayName ) - fgError ("Could not allocate space for display name."); + fgError( "Could not allocate space for display name." ); - for( i=1; i= argc ) - fgError( "-geometry parameter must be followed by window " - "geometry settings" ); - result = sscanf ( argv[i], "%dx%d+%d+%d", &x, &y, &w, &h ); + 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 ); - if ( result > 3 ) + if( result > 3 ) fgState.Size.Y = h; - if ( result > 2 ) + if( result > 2 ) fgState.Size.X = w; if( result > 1 ) @@ -397,45 +397,45 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) argv[ i - 1 ] = NULL; argv[ i ] = NULL; - (*pargc) -= 2; + ( *pargc ) -= 2; } else if( strcmp( argv[ i ], "-direct" ) == 0) { - if( fgState.TryDirectContext == FALSE ) + if( ! fgState.TryDirectContext ) fgError( "parameters ambiguity, -direct and -indirect " "cannot be both specified" ); - fgState.ForceDirectContext = TRUE; + fgState.ForceDirectContext = GL_TRUE; argv[ i ] = NULL; - (*pargc)--; + ( *pargc )--; } else if( strcmp( argv[ i ], "-indirect" ) == 0 ) { - if( fgState.ForceDirectContext == TRUE ) + if( fgState.ForceDirectContext ) fgError( "parameters ambiguity, -direct and -indirect " "cannot be both specified" ); - fgState.TryDirectContext = FALSE; + fgState.TryDirectContext = GL_FALSE; argv[ i ] = NULL; (*pargc)--; } else if( strcmp( argv[ i ], "-iconic" ) == 0 ) { - fgState.ForceIconic = TRUE; + fgState.ForceIconic = GL_TRUE; argv[ i ] = NULL; - (*pargc)--; + ( *pargc )--; } else if( strcmp( argv[ i ], "-gldebug" ) == 0 ) { - fgState.GLDebugSwitch = TRUE; + fgState.GLDebugSwitch = GL_TRUE; argv[ i ] = NULL; - (*pargc)--; + ( *pargc )--; } else if( strcmp( argv[ i ], "-sync" ) == 0 ) { - fgState.XSyncSwitch = TRUE; + fgState.XSyncSwitch = GL_TRUE; argv[ i ] = NULL; - (*pargc)--; + ( *pargc )--; } } @@ -448,9 +448,9 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) if( argv[ i ] == NULL ) { /* Guaranteed to end because there are "*pargc" arguments left */ - while ( argv[j] == NULL ) + while ( argv[ j ] == NULL ) j++; - argv[i] = argv[j] ; + argv[ i ] = argv[ j ] ; } } @@ -471,10 +471,10 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) * Check for the minus one settings for both position and size... */ if( fgState.Position.X < 0 || fgState.Position.Y < 0 ) - fgState.Position.Use = FALSE; + fgState.Position.Use = GL_FALSE; if( fgState.Size.X < 0 || fgState.Size.Y < 0 ) - fgState.Size.Use = FALSE; + fgState.Size.Use = GL_FALSE; if( displayName ) free( displayName ); @@ -485,17 +485,17 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) */ void FGAPIENTRY glutInitWindowPosition( int x, int y ) { - if( (x >= 0) && (y >= 0) ) + if( ( x >= 0 ) && ( y >= 0 ) ) { - fgState.Position.X = x; - fgState.Position.Y = y; - fgState.Position.Use = TRUE; + fgState.Position.X = x; + fgState.Position.Y = y; + fgState.Position.Use = GL_TRUE; } else { - fgState.Position.X = -1; - fgState.Position.Y = -1; - fgState.Position.Use = FALSE; + fgState.Position.X = -1; + fgState.Position.Y = -1; + fgState.Position.Use = GL_FALSE; } } @@ -504,17 +504,17 @@ void FGAPIENTRY glutInitWindowPosition( int x, int y ) */ void FGAPIENTRY glutInitWindowSize( int width, int height ) { - if( (width > 0) && (height > 0) ) + if( ( width > 0 ) && ( height > 0 ) ) { - fgState.Size.X = width; - fgState.Size.Y = height; - fgState.Size.Use = TRUE; + fgState.Size.X = width; + fgState.Size.Y = height; + fgState.Size.Use = GL_TRUE; } else { - fgState.Size.X = -1; - fgState.Size.Y = -1; - fgState.Size.Use = FALSE; + fgState.Size.X = -1; + fgState.Size.Y = -1; + fgState.Size.Use = GL_FALSE; } }