added warning and error callbacks to demo

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1369 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2012-07-24 15:03:53 +00:00
parent 0e41b344b8
commit fc3aa8f406
2 changed files with 39 additions and 2 deletions

View File

@ -131,6 +131,40 @@ Display(void)
glutSwapBuffers(); glutSwapBuffers();
} }
static void
Warning(const char *fmt, va_list ap)
{
printf("%6d Warning callback:\n");
/* print warning message */
vprintf(fmt, ap);
}
static void
Error(const char *fmt, va_list ap)
{
#define STRING_LENGTH 10
char dummy_string[STRING_LENGTH];
printf("%6d Error callback:\n");
/* print warning message */
vprintf(fmt, ap);
/* deInitialize the freeglut state */
/* This all goes haywire of course when the error occurs during deinitialize,
* one might want to call exit directly as its possible freeglut is messed
* up internally when error is called.
*/
printf("Error callback: calling glutExit() to prepare for clean exit\n");
glutExit();
/* terminate program */
printf ( "Please enter something to exit: " );
fgets ( dummy_string, STRING_LENGTH, stdin );
exit(1);
}
static void static void
Reshape(int width, int height) Reshape(int width, int height)
{ {
@ -407,7 +441,9 @@ MenuDestroy( void )
menudestroy_called = 1 ; menudestroy_called = 1 ;
printf ( "%6d Window %d MenuDestroy Callback\n", printf ( "%6d Window %d MenuDestroy Callback\n",
++sequence_number, window ) ; ++sequence_number, window ) ;
glutPostRedisplay () ;
if (window) /* When destroyed when shutting down, not always a window defined... */
glutPostRedisplay () ;
} }
static void static void
@ -434,6 +470,8 @@ main(int argc, char *argv[])
int menuID, subMenuA, subMenuB; int menuID, subMenuA, subMenuB;
glutInitWarningFunc(Warning);
glutInitErrorFunc(Error);
glutInitWindowSize(500, 250); glutInitWindowSize(500, 250);
glutInitWindowPosition ( 140, 140 ); glutInitWindowPosition ( 140, 140 );
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE ); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE );

View File

@ -545,7 +545,6 @@ static void fghActivateMenu( SFG_Window* window, int button )
window->State.MouseY + glutGet( GLUT_WINDOW_Y ) - menu->Y; window->State.MouseY + glutGet( GLUT_WINDOW_Y ) - menu->Y;
/* Menu status callback */ /* Menu status callback */
printf("Menu status callback: %p\n",fgState.MenuStatusCallback);
if (fgState.MenuStateCallback || fgState.MenuStatusCallback) if (fgState.MenuStateCallback || fgState.MenuStatusCallback)
{ {
fgStructure.CurrentMenu = menu; fgStructure.CurrentMenu = menu;