diff --git a/freeglut/freeglut/src/freeglut_callbacks.c b/freeglut/freeglut/src/freeglut_callbacks.c index 94c4dbd..38adc58 100644 --- a/freeglut/freeglut/src/freeglut_callbacks.c +++ b/freeglut/freeglut/src/freeglut_callbacks.c @@ -171,12 +171,7 @@ void FGAPIENTRY glutJoystickFunc( void (* callback) ( unsigned int, int, int, int ), int pollInterval ) { - if( !fgState.JoysticksInitialised ) - { - fgJoystickInit( 0 ); - fgJoystickInit( 1 ); - fgState.JoysticksInitialised = GL_TRUE; - } + fgInitialiseJoysticks (); SET_CALLBACK( Joystick ); fgStructure.Window->State.JoystickPollRate = pollInterval; diff --git a/freeglut/freeglut/src/freeglut_internal.h b/freeglut/freeglut/src/freeglut_internal.h index 56f8f24..a032851 100644 --- a/freeglut/freeglut/src/freeglut_internal.h +++ b/freeglut/freeglut/src/freeglut_internal.h @@ -704,10 +704,16 @@ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback ); void fgDestroyMenu( SFG_Menu* menu ); /* Joystick device management functions, defined in freeglut_joystick.c */ -void fgJoystickInit( int ident ); +int fgJoystickDetect( void ); +void fgInitialiseJoysticks( void ); void fgJoystickClose( void ); void fgJoystickPollWindow( SFG_Window* window ); +/* More joystick functions. Should these go into the API? */ +int glutJoystickGetNumAxes( int ident ); +int glutJoystickGetNumButtons( int ident ); +int glutJoystickNotWorking( int ident ); + /* * Helper function to enumerate through all registered windows * and one to enumerate all of a window's subwindows... diff --git a/freeglut/freeglut/src/freeglut_joystick.c b/freeglut/freeglut/src/freeglut_joystick.c index a61a708..185ef1b 100644 --- a/freeglut/freeglut/src/freeglut_joystick.c +++ b/freeglut/freeglut/src/freeglut_joystick.c @@ -450,7 +450,6 @@ static void fghJoystickAddHatElement ( SFG_Joystick* joy, CFDictionaryRef hat ); * The static joystick structure pointer */ #define MAX_NUM_JOYSTICKS 2 -static int fgNumberOfJoysticks = 0; static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ]; @@ -1528,7 +1527,7 @@ static void fghJoystickOpen( SFG_Joystick* joy ) /* * This function replaces the constructor method in the JS library. */ -void fgJoystickInit( int ident ) +static void fghJoystickInit( int ident ) { if( ident >= MAX_NUM_JOYSTICKS ) fgError( "Too large a joystick number: %d", ident ); @@ -1638,6 +1637,22 @@ void fgJoystickInit( int ident ) fghJoystickOpen( fgJoystick[ ident ] ); } +/* + * Try initializing all the joysticks (well, both of them) + */ +void fgInitialiseJoysticks ( void ) +{ + /* Initialization courtesy of OpenGLUT -- do we want it? */ + if( !fgState.JoysticksInitialised ) + { + int ident ; + for ( ident = 0; ident < MAX_NUM_JOYSTICKS; ident++ ) + fghJoystickInit( ident ); + + fgState.JoysticksInitialised = GL_TRUE; + } +} + /* * */ @@ -1722,12 +1737,38 @@ void fgJoystickPollWindow( SFG_Window* window ) } /* - * PWO: These jsJoystick class methods have not been implemented. + * Implementation for glutDeviceGet(GLUT_HAS_JOYSTICK) + */ +int fgJoystickDetect( void ) +{ + int ident; + + fgInitialiseJoysticks (); + + if ( !fgJoystick ) + return 0; + + if ( !fgState.JoysticksInitialised ) + return 0; + + for( ident=0; identerror ) + return 1; + + return 0; +} + +/* + * Joystick information functions */ int glutJoystickGetNumAxes( int ident ) { return fgJoystick[ ident ]->num_axes; } +int glutJoystickGetNumButtons( int ident ) +{ + return fgJoystick[ ident ]->num_buttons; +} int glutJoystickNotWorking( int ident ) { return fgJoystick[ ident ]->error; diff --git a/freeglut/freeglut/src/freeglut_state.c b/freeglut/freeglut/src/freeglut_state.c index f8b70e9..cf478a8 100644 --- a/freeglut/freeglut/src/freeglut_state.c +++ b/freeglut/freeglut/src/freeglut_state.c @@ -528,13 +528,21 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat ) #endif - case GLUT_JOYSTICK_POLL_RATE: case GLUT_HAS_JOYSTICK: + return fgJoystickDetect (); + case GLUT_OWNS_JOYSTICK: + return fgState.JoysticksInitialised; + + case GLUT_JOYSTICK_POLL_RATE: + return fgStructure.Window ? fgStructure.Window->State.JoystickPollRate : 0; + + /* The following two are only for Joystick 0 but this is an improvement */ case GLUT_JOYSTICK_BUTTONS: + return glutJoystickGetNumButtons ( 0 ); + case GLUT_JOYSTICK_AXES: - /* XXX WARNING: THIS IS A BIG LIE! */ - return 0; + return glutJoystickGetNumAxes ( 0 ); case GLUT_HAS_SPACEBALL: case GLUT_HAS_DIAL_AND_BUTTON_BOX: