xref: /haiku/src/libs/glut/glut_util.c (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2  * Copyright 1994-1997 Mark Kilgard, All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * GPL licensing not permitted.
6  *
7  * Authors:
8  *      Mark Kilgard
9  */
10 
11 
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #include <stdio.h>
16 
17 #include "glutint.h"
18 
19 
20 /* strdup is actually not a standard ANSI C or POSIX routine
21    so implement a private one for GLUT.  OpenVMS does not have a
22    strdup; Linux's standard libc doesn't declare strdup by default
23    (unless BSD or SVID interfaces are requested). */
24 char *
25 __glutStrdup(const char *string)
26 {
27   char *copy;
28 
29   copy = (char*) malloc(strlen(string) + 1);
30   if (copy == NULL)
31     return NULL;
32   strcpy(copy, string);
33   return copy;
34 }
35 
36 void
37 __glutWarning(const char *format,...)
38 {
39   va_list args;
40 
41   va_start(args, format);
42   fprintf(stderr, "GLUT: Warning in %s: ",
43     __glutProgramName ? __glutProgramName : "(unamed)");
44   vfprintf(stderr, format, args);
45   va_end(args);
46   putc('\n', stderr);
47 }
48 
49 /* CENTRY */
50 void APIENTRY
51 glutReportErrors(void)
52 {
53   GLenum error;
54 
55   while ((error = glGetError()) != GL_NO_ERROR)
56     __glutWarning("GL error: %s", gluErrorString(error));
57 }
58 /* ENDCENTRY */
59 
60 void
61 __glutFatalError(const char *format,...)
62 {
63   va_list args;
64 
65   va_start(args, format);
66   fprintf(stderr, "GLUT: Fatal Error in %s: ",
67     __glutProgramName ? __glutProgramName : "(unamed)");
68   vfprintf(stderr, format, args);
69   va_end(args);
70   putc('\n', stderr);
71   exit(1);
72 }
73 
74 void
75 __glutFatalUsage(const char *format,...)
76 {
77   va_list args;
78 
79   va_start(args, format);
80   fprintf(stderr, "GLUT: Fatal API Usage in %s: ",
81     __glutProgramName ? __glutProgramName : "(unamed)");
82   vfprintf(stderr, format, args);
83   va_end(args);
84   putc('\n', stderr);
85   abort();
86 }
87