Addressing feature request 2116152 -- adding an fgError exit callback routine -- patch from Chris Marshall in e-mail dated 10/30/2010 2:06 PM

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@877 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
fayjf 2010-11-01 04:13:54 +00:00
parent c7aaa1bc6b
commit e5e5aebedf
8 changed files with 84 additions and 20 deletions

View File

@ -95,5 +95,5 @@ if test "x$enable_debug" = xyes; then
fi
# Generate output.
AC_CONFIG_FILES([Makefile doc/Makefile include/GL/Makefile include/Makefile progs/Makefile progs/demos/CallbackMaker/Makefile progs/demos/Fractals/Makefile progs/demos/Fractals_random/Makefile progs/demos/Lorenz/Makefile progs/demos/Makefile progs/demos/One/Makefile progs/demos/shapes/Makefile progs/demos/smooth_opengl3/Makefile progs/demos/spaceball/Makefile src/Makefile])
AC_CONFIG_FILES([Makefile doc/Makefile include/GL/Makefile include/Makefile progs/Makefile progs/demos/CallbackMaker/Makefile progs/demos/Error/Makefile progs/demos/Fractals/Makefile progs/demos/Fractals_random/Makefile progs/demos/Lorenz/Makefile progs/demos/Makefile progs/demos/One/Makefile progs/demos/shapes/Makefile progs/demos/smooth_opengl3/Makefile progs/demos/spaceball/Makefile src/Makefile])
AC_OUTPUT

View File

@ -202,6 +202,12 @@ FGAPI void FGAPIENTRY glutInitContextVersion( int majorVersion, int minorVers
FGAPI void FGAPIENTRY glutInitContextFlags( int flags );
FGAPI void FGAPIENTRY glutInitContextProfile( int profile );
/* to get the typedef for va_list */
#include <stdarg.h>
FGAPI void FGAPIENTRY glutInitErrorFunc( void (* vError)( const char *fmt, va_list ap ) );
FGAPI void FGAPIENTRY glutInitWarningFunc( void (* vWarning)( const char *fmt, va_list ap ) );
/*
* GLUT API macro definitions -- the display mode definitions
*/

View File

@ -1,2 +1,2 @@
EXTRA_DIST = demos.dsw
SUBDIRS = CallbackMaker Fractals Fractals_random Lorenz One shapes smooth_opengl3 spaceball
SUBDIRS = CallbackMaker Error Fractals Fractals_random Lorenz One shapes smooth_opengl3 spaceball

View File

@ -196,6 +196,8 @@ static GLUTproc fghGetGLUTProcAddress( const char* procName )
CHECK_NAME(glutInitContextVersion);
CHECK_NAME(glutInitContextFlags);
CHECK_NAME(glutInitContextProfile);
CHECK_NAME(glutInitErrorFunc);
CHECK_NAME(glutInitWarningFunc);
#undef CHECK_NAME
return NULL;

View File

@ -91,7 +91,9 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
1, /* MajorVersion */
0, /* MajorVersion */
0, /* ContextFlags */
0 /* ContextProfile */
0, /* ContextProfile */
NULL, /* ErrorFunc */
NULL /* WarningFunc */
};
@ -1143,4 +1145,24 @@ void FGAPIENTRY glutInitContextProfile( int profile )
fgState.ContextProfile = profile;
}
/* -------------- User Defined Error/Warning Handler Support -------------- */
/*
* Sets the user error handler (note the use of va_list for the args to the fmt)
*/
void FGAPIENTRY glutInitErrorFunc( void (* vfgError) ( const char *fmt, va_list ap ) )
{
/* This allows user programs to handle freeglut errors */
fgState.ErrorFunc = vfgError;
}
/*
* Sets the user warning handler (note the use of va_list for the args to the fmt)
*/
void FGAPIENTRY glutInitWarningFunc( void (* vfgWarning) ( const char *fmt, va_list ap ) )
{
/* This allows user programs to handle freeglut warnings */
fgState.ErrorFunc = vfgWarning;
}
/*** END OF FILE ***/

View File

@ -129,6 +129,7 @@
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdarg.h>
/* These are included based on autoconf directives. */
#ifdef HAVE_SYS_TYPES_H
@ -243,6 +244,10 @@ typedef void (* FGCBMenuStatus )( int, int, int );
/* The callback used when creating/using menus */
typedef void (* FGCBMenu )( int );
/* The FreeGLUT error/warning handler type definition */
typedef void (* FGError ) ( const char *fmt, va_list ap);
typedef void (* FGWarning ) ( const char *fmt, va_list ap);
/* A list structure */
typedef struct tagSFG_List SFG_List;
@ -333,6 +338,8 @@ struct tagSFG_State
int MinorVersion; /* Minor OpenGL context version */
int ContextFlags; /* OpenGL context flags */
int ContextProfile; /* OpenGL context profile */
FGError ErrorFunc; /* User defined error handler */
FGWarning WarningFunc; /* User defined warning handler */
};
/* The structure used by display initialization in freeglut_init.c */

View File

@ -338,37 +338,62 @@ void fgError( const char *fmt, ... )
{
va_list ap;
va_start( ap, fmt );
if (fgState.ErrorFunc) {
fprintf( stderr, "freeglut ");
if( fgState.ProgramName )
fprintf( stderr, "(%s): ", fgState.ProgramName );
VFPRINTF( stderr, fmt, ap );
fprintf( stderr, "\n" );
va_start( ap, fmt );
va_end( ap );
/* call user set error handler here */
fgState.ErrorFunc(fmt, ap);
if ( fgState.Initialised )
fgDeinitialize ();
va_end( ap );
exit( 1 );
} else {
va_start( ap, fmt );
fprintf( stderr, "freeglut ");
if( fgState.ProgramName )
fprintf( stderr, "(%s): ", fgState.ProgramName );
VFPRINTF( stderr, fmt, ap );
fprintf( stderr, "\n" );
va_end( ap );
if ( fgState.Initialised )
fgDeinitialize ();
exit( 1 );
}
}
void fgWarning( const char *fmt, ... )
{
va_list ap;
va_start( ap, fmt );
if (fgState.WarningFunc) {
fprintf( stderr, "freeglut ");
if( fgState.ProgramName )
fprintf( stderr, "(%s): ", fgState.ProgramName );
VFPRINTF( stderr, fmt, ap );
fprintf( stderr, "\n" );
va_start( ap, fmt );
va_end( ap );
/* call user set warning handler here */
fgState.WarningFunc(fmt, ap);
va_end( ap );
} else {
va_start( ap, fmt );
fprintf( stderr, "freeglut ");
if( fgState.ProgramName )
fprintf( stderr, "(%s): ", fgState.ProgramName );
VFPRINTF( stderr, fmt, ap );
fprintf( stderr, "\n" );
va_end( ap );
}
}
/*
* Indicates whether Joystick events are being used by ANY window.
*

View File

@ -143,6 +143,8 @@ EXPORTS
glutInitContextFlags
glutInitContextVersion
glutInitContextProfile
glutInitErrorFunc
glutInitWarningFunc
__glutInitWithExit
__glutCreateWindowWithExit
__glutCreateMenuWithExit