1 /*
2  * ------------------------------------------
3  * user_error_handler.c
4  *
5  * This is a sample program showing a basic
6  * user defined error handlers with FreeGLUT
7  * ------------------------------------------
8  */
9 
10 #include <GL/freeglut.h>
11 
12 /*
13  * ------------------------------------------
14  * Declare our own Error handler for FreeGLUT
15  * ------------------------------------------
16  */
17 
18 /* This declares the vprintf() routine */
19 #include <stdio.h>
20 
21 /* This declares the va_list type */
22 #include <stdarg.h>
23 
24 /* The new handler looks like a vprintf prototype */
myError(const char * fmt,va_list ap)25 void myError (const char *fmt, va_list ap)
26 {
27     fprintf(stderr, "myError: Entering user defined error handler\n");
28 
29     /* print warning message */
30     fprintf(stderr, "myError:");
31     vfprintf(stderr, fmt, ap);
32     fprintf(stderr, "\n");
33 
34     /* deInitialize the freeglut state */
35     fprintf(stderr, "myError: Calling glutExit()\n");
36     glutExit();
37 
38     /* terminate error handler appropriately */
39     fprintf(stderr, "myError: Exit-ing handler routine\n");
40 
41     exit(1);
42 }
43 
44 /*
45  * ------------------------------------------
46  * Just enough code to create the error to
47  * demonstrate the user defined handler
48  * ------------------------------------------
49  */
main(int argc,char ** argv)50 int main(int argc, char** argv)
51 {
52     glutInitErrorFunc(&myError);
53     glutCreateWindow ("error test");  /* This is an error! */
54     glutInit(&argc, argv);            /* Should be called
55                                          after glutInit() */
56     glutMainLoop();
57     return 0;
58 }
59