From: <jt...@us...> - 2015-03-07 18:54:02
|
Revision: 1750 http://sourceforge.net/p/freeglut/code/1750 Author: jtsiomb Date: 2015-03-07 18:53:54 +0000 (Sat, 07 Mar 2015) Log Message: ----------- 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 Added Paths: ----------- trunk/freeglut/freeglut/progs/demos/init_error_func/ trunk/freeglut/freeglut/progs/demos/init_error_func/init_error_func.c Added: trunk/freeglut/freeglut/progs/demos/init_error_func/init_error_func.c =================================================================== --- trunk/freeglut/freeglut/progs/demos/init_error_func/init_error_func.c (rev 0) +++ trunk/freeglut/freeglut/progs/demos/init_error_func/init_error_func.c 2015-03-07 18:53:54 UTC (rev 1750) @@ -0,0 +1,58 @@ +/* + * ------------------------------------------ + * user_error_handler.c + * + * This is a sample program showing a basic + * user defined error handlers with FreeGLUT + * ------------------------------------------ + */ + +#include <GL/freeglut.h> + +/* + * ------------------------------------------ + * Declare our own Error handler for FreeGLUT + * ------------------------------------------ + */ + +/* This declares the vprintf() routine */ +#include <stdio.h> + +/* This declares the va_list type */ +#include <stdarg.h> + +/* 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; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |