diff --git a/freeglut/freeglut/src/freeglut_init.c b/freeglut/freeglut/src/freeglut_init.c index 26cb353..70207e0 100644 --- a/freeglut/freeglut/src/freeglut_init.c +++ b/freeglut/freeglut/src/freeglut_init.c @@ -58,6 +58,7 @@ SFG_Display fgDisplay; SFG_State fgState = { { -1, -1, FALSE }, /* Position */ { 300, 300, TRUE }, /* Size */ GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */ + FALSE, /* Initalized */ FALSE, /* ForceDirectContext */ TRUE, /* TryDirectContext */ FALSE, /* ForceIconic */ @@ -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 */ @@ -312,17 +317,12 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) 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( ); -#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 */ { diff --git a/freeglut/freeglut/src/freeglut_internal.h b/freeglut/freeglut/src/freeglut_internal.h index 77e47ea..659742b 100644 --- a/freeglut/freeglut/src/freeglut_internal.h +++ b/freeglut/freeglut/src/freeglut_internal.h @@ -218,6 +218,8 @@ struct tagSFG_State SFG_XYUse Size; /* The default windows' size */ unsigned int DisplayMode; /* Display mode for new windows */ + GLboolean Initalized; /* Freeglut has been initalized */ + GLboolean ForceDirectContext; /* Force direct rendering? */ GLboolean TryDirectContext; /* What about giving a try to? */ @@ -643,7 +645,7 @@ extern SFG_State fgState; * A call to this function makes us sure that the Display and Structure * subsystems have been properly initialized and are ready to be used */ -#define freeglut_assert_ready assert( fgState.Time.Set ); +#define freeglut_assert_ready assert( fgState.Initalized ); /* * Following definitions are somewhat similiar to GLib's, diff --git a/freeglut/freeglut/src/freeglut_main.c b/freeglut/freeglut/src/freeglut_main.c index 823087b..6a08d2d 100644 --- a/freeglut/freeglut/src/freeglut_main.c +++ b/freeglut/freeglut/src/freeglut_main.c @@ -296,19 +296,31 @@ static void fghCheckTimers( void ) */ long fgElapsedTime( void ) { + if (fgState.Time.Set) + { #if TARGET_HOST_UNIX_X11 - struct timeval now; - long elapsed; + struct timeval now; + long elapsed; - gettimeofday( &now, NULL ); + gettimeofday( &now, NULL ); - elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000; - elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000; + elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000; + elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000; - return elapsed; + return elapsed; #elif TARGET_HOST_WIN32 - return timeGetTime() - fgState.Time.Value; + return timeGetTime() - fgState.Time.Value; #endif + } + else + { +#if TARGET_HOST_UNIX_X11 + gettimeofday( &fgState.Time.Value, NULL ); +#elif TARGET_HOST_WIN32 + fgState.Time.Value = timeGetTime( ); +#endif + fgState.Time.Set = TRUE; + } } /* diff --git a/freeglut/freeglut/src/freeglut_state.c b/freeglut/freeglut/src/freeglut_state.c index 4b1aed8..0ddceaf 100644 --- a/freeglut/freeglut/src/freeglut_state.c +++ b/freeglut/freeglut/src/freeglut_state.c @@ -127,8 +127,14 @@ int FGAPIENTRY glutGet( GLenum eWhat ) int returnValue ; GLboolean boolValue ; - if ( eWhat == GLUT_INIT_STATE ) - return ( fgState.Time.Set ) ; + switch (eWhat) + { + case GLUT_INIT_STATE: + return ( fgState.Initalized ) ; + + case GLUT_ELAPSED_TIME: + return( fgElapsedTime() ); + } freeglut_assert_ready; @@ -137,9 +143,6 @@ int FGAPIENTRY glutGet( GLenum eWhat ) */ switch( eWhat ) { - case GLUT_ELAPSED_TIME: - return( fgElapsedTime() ); - /* * Following values are stored in fgState and fgDisplay global structures */ diff --git a/freeglut/freeglut/src/freeglut_structure.c b/freeglut/freeglut/src/freeglut_structure.c index 949747b..8a19aff 100644 --- a/freeglut/freeglut/src/freeglut_structure.c +++ b/freeglut/freeglut/src/freeglut_structure.c @@ -83,7 +83,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, * If the freeglut internals haven't been initialized yet, * do it now. Hack's idea courtesy of Chris Purnell... */ - if( !fgState.Time.Set ) + if( !fgState.Initalized ) glutInit( &fakeArgc, NULL ); /* @@ -136,7 +136,7 @@ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback ) * If the freeglut internals haven't been initialized yet, * do it now. Hack's idea courtesy of Chris Purnell... */ - if( !fgState.Time.Set ) + if( !fgState.Initalized ) glutInit( &fakeArgc, NULL ); menu->ParentWindow = fgStructure.Window; diff --git a/freeglut/freeglut/src/freeglut_window.c b/freeglut/freeglut/src/freeglut_window.c index 61df8fd..4820ad0 100644 --- a/freeglut/freeglut/src/freeglut_window.c +++ b/freeglut/freeglut/src/freeglut_window.c @@ -960,7 +960,8 @@ void FGAPIENTRY glutFullScreen( void ) fgDisplay.ScreenWidth, fgDisplay.ScreenHeight ); - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ + + XFlush( fgDisplay.Display ); /* This is needed */ XTranslateCoordinates( fgDisplay.Display,