Fixed issue where setting the same callback with different user pointer wouldn't...
[freeglut] / src / fg_init.c
index ae87212..c3c00e5 100644 (file)
@@ -70,9 +70,11 @@ SFG_State fgState = { { -1, -1, GL_FALSE },  /* Position */
                       { NULL, NULL },         /* Timers */
                       { NULL, NULL },         /* FreeTimers */
                       NULL,                   /* IdleCallback */
+                      NULL,                   /* IdleCallbackData */
                       0,                      /* ActiveMenus */
                       NULL,                   /* MenuStateCallback */
                       NULL,                   /* MenuStatusCallback */
+                      NULL,                   /* MenuStatusCallbackData */
                       FREEGLUT_MENU_FONT,
                       { -1, -1, GL_TRUE },    /* GameModeSize */
                       -1,                     /* GameModeDepth */
@@ -95,7 +97,9 @@ SFG_State fgState = { { -1, -1, GL_FALSE },  /* Position */
                       0,                      /* OpenGL ContextProfile */
                       0,                      /* HasOpenGL20 */
                       NULL,                   /* ErrorFunc */
-                      NULL                    /* WarningFunc */
+                      NULL,                   /* ErrorFuncData */
+                      NULL,                   /* WarningFunc */
+                      NULL                    /* WarningFuncData */
 };
 
 
@@ -298,9 +302,11 @@ void fgDeinitialize( void )
     fgListInit( &fgState.Timers );
     fgListInit( &fgState.FreeTimers );
 
-    fgState.IdleCallback = NULL;
-    fgState.MenuStateCallback = ( FGCBMenuState )NULL;
-    fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL;
+    fgState.IdleCallback           = ( FGCBIdleUC )NULL;
+    fgState.IdleCallbackData       = NULL;
+    fgState.MenuStateCallback      = ( FGCBMenuState )NULL;
+    fgState.MenuStatusCallback     = ( FGCBMenuStatusUC )NULL;
+    fgState.MenuStatusCallbackData = NULL;
 
     fgState.SwapCount   = 0;
     fgState.SwapTime    = 0;
@@ -668,19 +674,57 @@ void FGAPIENTRY glutInitContextProfile( int profile )
 /*
  * Sets the user error handler (note the use of va_list for the args to the fmt)
  */
-void FGAPIENTRY glutInitErrorFunc( FGError callback )
+void FGAPIENTRY glutInitErrorFuncUcall( FGErrorUC callback, FGCBUserData userData )
 {
     /* This allows user programs to handle freeglut errors */
     fgState.ErrorFunc = callback;
+    fgState.ErrorFuncData = userData;
+}
+
+static void fghInitErrorFuncCallback( const char *fmt, va_list ap, FGCBUserData userData )
+{
+    FGError callback = (FGError)userData;
+    callback( fmt, ap );
+}
+
+void FGAPIENTRY glutInitErrorFunc( FGError callback )
+{
+       if (callback)
+       {
+               glutInitErrorFuncUcall( fghInitErrorFuncCallback, (FGCBUserData)callback );
+       }
+       else
+       {
+               glutInitErrorFuncUcall( NULL, NULL );
+       }
 }
 
 /*
  * Sets the user warning handler (note the use of va_list for the args to the fmt)
  */
-void FGAPIENTRY glutInitWarningFunc( FGWarning callback )
+void FGAPIENTRY glutInitWarningFuncUcall( FGWarningUC callback, FGCBUserData userData )
 {
     /* This allows user programs to handle freeglut warnings */
     fgState.WarningFunc = callback;
+    fgState.WarningFuncData = userData;
+}
+
+static void fghInitWarningFuncCallback( const char *fmt, va_list ap, FGCBUserData userData )
+{
+    FGWarning callback = (FGWarning)userData;
+    callback( fmt, ap );
+}
+
+void FGAPIENTRY glutInitWarningFunc( FGWarning callback )
+{
+       if (callback)
+       {
+               glutInitWarningFuncUcall( fghInitWarningFuncCallback, (FGCBUserData)callback );
+       }
+       else
+       {
+               glutInitWarningFuncUcall( NULL, NULL );
+       }
 }
 
 /*** END OF FILE ***/