added error check (John Fay)
[freeglut] / src / freeglut_state.c
index f8b70e9..c972713 100644 (file)
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include <GL/freeglut.h>
 #include "freeglut_internal.h"
 
@@ -72,7 +68,7 @@ static int fghGetConfig( int attribute )
  */
 void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
 {
-    freeglut_assert_ready;
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetOption" );
 
     /*
      * XXX In chronological code add order.  (WHY in that order?)
@@ -142,7 +138,7 @@ int FGAPIENTRY glutGet( GLenum eWhat )
         return fgElapsedTime();
     }
 
-    freeglut_assert_ready;
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGet" );
 
     /* XXX In chronological code add order.  (WHY in that order?) */
     switch( eWhat )
@@ -465,7 +461,7 @@ int FGAPIENTRY glutGet( GLenum eWhat )
  */
 int FGAPIENTRY glutDeviceGet( GLenum eWhat )
 {
-    freeglut_assert_ready;
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" );
 
     /* XXX WARNING: we are mostly lying in this function. */
     switch( eWhat )
@@ -528,13 +524,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;
+
+    /* XXX 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:
@@ -551,8 +555,7 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
         return fgStructure.Window ? fgStructure.Window->State.IgnoreKeyRepeat : 0;
 
     case GLUT_DEVICE_KEY_REPEAT:
-        /* XXX WARNING: THIS IS A BIG LIE! */
-        return GLUT_KEY_REPEAT_DEFAULT;
+        return fgState.KeyRepeat;
 
     default:
         fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
@@ -568,6 +571,7 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
  */
 int FGAPIENTRY glutGetModifiers( void )
 {
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetModifiers" );
     if( fgState.Modifiers == 0xffffffff )
     {
         fgWarning( "glutGetModifiers() called outside an input callback" );
@@ -582,7 +586,7 @@ int FGAPIENTRY glutGetModifiers( void )
  */
 int FGAPIENTRY glutLayerGet( GLenum eWhat )
 {
-    freeglut_assert_ready;
+    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLayerGet" );
 
     /*
      * This is easy as layers are not implemented ;-)