From: John Tsiombikas Date: Sat, 7 Mar 2015 18:53:54 +0000 (+0000) Subject: added the init error handler example program contributed by Chris Marshall X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=freeglut;a=commitdiff_plain;h=66baf810dcc4db19723a2d622b49b1dfb6815047 added the init error handler example program contributed by Chris Marshall Not building it as part of the demos yet, since it was submitted quite late in the 3.0 release process git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1750 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/progs/demos/init_error_func/init_error_func.c b/progs/demos/init_error_func/init_error_func.c new file mode 100644 index 0000000..de5cf28 --- /dev/null +++ b/progs/demos/init_error_func/init_error_func.c @@ -0,0 +1,58 @@ +/* + * ------------------------------------------ + * user_error_handler.c + * + * This is a sample program showing a basic + * user defined error handlers with FreeGLUT + * ------------------------------------------ + */ + +#include + +/* + * ------------------------------------------ + * Declare our own Error handler for FreeGLUT + * ------------------------------------------ + */ + +/* This declares the vprintf() routine */ +#include + +/* This declares the va_list type */ +#include + +/* The new handler looks like a vprintf prototype */ +void myError (const char *fmt, va_list ap) +{ + fprintf(stderr, "myError: Entering user defined error handler\n"); + + /* print warning message */ + fprintf(stderr, "myError:"); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + + /* deInitialize the freeglut state */ + fprintf(stderr, "myError: Calling glutExit()\n"); + glutExit(); + + /* terminate error handler appropriately */ + fprintf(stderr, "myError: Exit-ing handler routine\n"); + + exit(1); +} + +/* + * ------------------------------------------ + * Just enough code to create the error to + * demonstrate the user defined handler + * ------------------------------------------ + */ +int main(int argc, char** argv) +{ + glutInitErrorFunc(&myError); + glutCreateWindow ("error test"); /* This is an error! */ + glutInit(&argc, argv); /* Should be called + after glutInit() */ + glutMainLoop(); + return 0; +}