Added a new state variable "Initalized".
Replaced referenced to Time.Set with this new variable where appropriate. fgElapsedTime() now set the start time if Time.Set is false. Moved glutGet(GLUT_ELAPSED_TIME) handling to before the assert. git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@348 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
6895440554
commit
2b78c976ea
@ -58,6 +58,7 @@ SFG_Display fgDisplay;
|
|||||||
SFG_State fgState = { { -1, -1, FALSE }, /* Position */
|
SFG_State fgState = { { -1, -1, FALSE }, /* Position */
|
||||||
{ 300, 300, TRUE }, /* Size */
|
{ 300, 300, TRUE }, /* Size */
|
||||||
GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */
|
GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */
|
||||||
|
FALSE, /* Initalized */
|
||||||
FALSE, /* ForceDirectContext */
|
FALSE, /* ForceDirectContext */
|
||||||
TRUE, /* TryDirectContext */
|
TRUE, /* TryDirectContext */
|
||||||
FALSE, /* ForceIconic */
|
FALSE, /* ForceIconic */
|
||||||
@ -197,6 +198,8 @@ void fgInitialize( const char* displayName )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
fgJoystickInit( 0 );
|
fgJoystickInit( 0 );
|
||||||
|
|
||||||
|
fgState.Initalized = GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -206,13 +209,15 @@ void fgDeinitialize( void )
|
|||||||
{
|
{
|
||||||
SFG_Timer *timer;
|
SFG_Timer *timer;
|
||||||
|
|
||||||
if( !fgState.Time.Set )
|
if( !fgState.Initalized )
|
||||||
{
|
{
|
||||||
fgWarning( "fgDeinitialize(): fgState.Timer is null => "
|
fgWarning( "fgDeinitialize(): "
|
||||||
"no valid initialization has been performed" );
|
"no valid initialization has been performed" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fgState.Initalized = GL_FALSE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there was a menu created, destroy the rendering context
|
* If there was a menu created, destroy the rendering context
|
||||||
*/
|
*/
|
||||||
@ -312,17 +317,12 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
|
|||||||
if( !fgState.ProgramName )
|
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 )
|
if( fgState.Initalized )
|
||||||
fgError( "illegal glutInit() reinitialization attemp" );
|
fgError( "illegal glutInit() reinitialization attemp" );
|
||||||
|
|
||||||
fgCreateStructure( );
|
fgCreateStructure( );
|
||||||
|
|
||||||
#if TARGET_HOST_UNIX_X11
|
fgElapsedTime( );
|
||||||
gettimeofday( &fgState.Time.Value, NULL );
|
|
||||||
#elif TARGET_HOST_WIN32
|
|
||||||
fgState.Time.Value = timeGetTime( );
|
|
||||||
#endif
|
|
||||||
fgState.Time.Set = TRUE;
|
|
||||||
|
|
||||||
/* check if GLUT_FPS env var is set */
|
/* check if GLUT_FPS env var is set */
|
||||||
{
|
{
|
||||||
|
@ -218,6 +218,8 @@ struct tagSFG_State
|
|||||||
SFG_XYUse Size; /* The default windows' size */
|
SFG_XYUse Size; /* The default windows' size */
|
||||||
unsigned int DisplayMode; /* Display mode for new windows */
|
unsigned int DisplayMode; /* Display mode for new windows */
|
||||||
|
|
||||||
|
GLboolean Initalized; /* Freeglut has been initalized */
|
||||||
|
|
||||||
GLboolean ForceDirectContext; /* Force direct rendering? */
|
GLboolean ForceDirectContext; /* Force direct rendering? */
|
||||||
GLboolean TryDirectContext; /* What about giving a try to? */
|
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
|
* A call to this function makes us sure that the Display and Structure
|
||||||
* subsystems have been properly initialized and are ready to be used
|
* 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,
|
* Following definitions are somewhat similiar to GLib's,
|
||||||
|
@ -296,19 +296,31 @@ static void fghCheckTimers( void )
|
|||||||
*/
|
*/
|
||||||
long fgElapsedTime( void )
|
long fgElapsedTime( void )
|
||||||
{
|
{
|
||||||
|
if (fgState.Time.Set)
|
||||||
|
{
|
||||||
#if TARGET_HOST_UNIX_X11
|
#if TARGET_HOST_UNIX_X11
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
long elapsed;
|
long elapsed;
|
||||||
|
|
||||||
gettimeofday( &now, NULL );
|
gettimeofday( &now, NULL );
|
||||||
|
|
||||||
elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
|
elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
|
||||||
elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
|
elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
|
||||||
|
|
||||||
return elapsed;
|
return elapsed;
|
||||||
#elif TARGET_HOST_WIN32
|
#elif TARGET_HOST_WIN32
|
||||||
return timeGetTime() - fgState.Time.Value;
|
return timeGetTime() - fgState.Time.Value;
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -127,8 +127,14 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
|||||||
int returnValue ;
|
int returnValue ;
|
||||||
GLboolean boolValue ;
|
GLboolean boolValue ;
|
||||||
|
|
||||||
if ( eWhat == GLUT_INIT_STATE )
|
switch (eWhat)
|
||||||
return ( fgState.Time.Set ) ;
|
{
|
||||||
|
case GLUT_INIT_STATE:
|
||||||
|
return ( fgState.Initalized ) ;
|
||||||
|
|
||||||
|
case GLUT_ELAPSED_TIME:
|
||||||
|
return( fgElapsedTime() );
|
||||||
|
}
|
||||||
|
|
||||||
freeglut_assert_ready;
|
freeglut_assert_ready;
|
||||||
|
|
||||||
@ -137,9 +143,6 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
|||||||
*/
|
*/
|
||||||
switch( eWhat )
|
switch( eWhat )
|
||||||
{
|
{
|
||||||
case GLUT_ELAPSED_TIME:
|
|
||||||
return( fgElapsedTime() );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Following values are stored in fgState and fgDisplay global structures
|
* Following values are stored in fgState and fgDisplay global structures
|
||||||
*/
|
*/
|
||||||
|
@ -83,7 +83,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
|
|||||||
* If the freeglut internals haven't been initialized yet,
|
* If the freeglut internals haven't been initialized yet,
|
||||||
* do it now. Hack's idea courtesy of Chris Purnell...
|
* do it now. Hack's idea courtesy of Chris Purnell...
|
||||||
*/
|
*/
|
||||||
if( !fgState.Time.Set )
|
if( !fgState.Initalized )
|
||||||
glutInit( &fakeArgc, NULL );
|
glutInit( &fakeArgc, NULL );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -136,7 +136,7 @@ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback )
|
|||||||
* If the freeglut internals haven't been initialized yet,
|
* If the freeglut internals haven't been initialized yet,
|
||||||
* do it now. Hack's idea courtesy of Chris Purnell...
|
* do it now. Hack's idea courtesy of Chris Purnell...
|
||||||
*/
|
*/
|
||||||
if( !fgState.Time.Set )
|
if( !fgState.Initalized )
|
||||||
glutInit( &fakeArgc, NULL );
|
glutInit( &fakeArgc, NULL );
|
||||||
|
|
||||||
menu->ParentWindow = fgStructure.Window;
|
menu->ParentWindow = fgStructure.Window;
|
||||||
|
@ -960,7 +960,8 @@ void FGAPIENTRY glutFullScreen( void )
|
|||||||
fgDisplay.ScreenWidth,
|
fgDisplay.ScreenWidth,
|
||||||
fgDisplay.ScreenHeight
|
fgDisplay.ScreenHeight
|
||||||
);
|
);
|
||||||
XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
|
|
||||||
|
XFlush( fgDisplay.Display ); /* This is needed */
|
||||||
|
|
||||||
XTranslateCoordinates(
|
XTranslateCoordinates(
|
||||||
fgDisplay.Display,
|
fgDisplay.Display,
|
||||||
|
Reference in New Issue
Block a user