1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef __BZFGL_H__
14 #define __BZFGL_H__
15 
16 /** this file contains headers necessary for opengl */
17 
18 #include "common.h"
19 
20 #include <GL/glew.h>
21 
22 #ifndef GL_VERSION_1_1
23 # error OpenGL version 1.1 functionality is required
24 #endif
25 
26 
27 /* These will track glBegin/End pairs to make sure that they match */
28 #ifdef DEBUG
29 #include <assert.h>
30 extern int __beginendCount;
31 #define glBegin(_value) {\
32   if (__beginendCount==0) { \
33     __beginendCount++;\
34   } else {\
35     std::cerr << "ERROR: glBegin called on " << __FILE__ << ':' << __LINE__ << " without calling glEnd before\n"; \
36     assert(__beginendCount==0 && "glBegin called without glEnd"); \
37   } \
38   glBegin(_value);\
39 }
40 #define glEnd() {\
41   if (__beginendCount==0) { \
42     std::cerr << "ERROR: glEnd called on " << __FILE__ << ':' << __LINE__ << " without calling glBegin before\n"; \
43     assert(__beginendCount!=0 && "glEnd called without glBegin"); \
44   } else {\
45     __beginendCount--;\
46   } \
47   glEnd();\
48 }
49 #endif
50 
51 
52 // glGenTextures() should never return 0
53 #define INVALID_GL_TEXTURE_ID ((GLuint) 0)
54 
55 // glGenLists() will only return 0 for errors
56 #define INVALID_GL_LIST_ID ((GLuint) 0)
57 
58 
59 /* Protect us from ourselves. Warn when these
60  * are called inside of the wrong context code
61  * sections (freeing and initializing).
62  */
63 //#define DEBUG_GL_MATRIX_STACKS
64 #ifdef DEBUG
65 #  define glNewList(list,mode)          bzNewList((list), (mode))
66 #  define glGenLists(count)         bzGenLists((count))
67 #  define glGenTextures(count, textures)    bzGenTextures((count), (textures))
68 #  ifdef DEBUG_GL_MATRIX_STACKS
69 #    define glPushMatrix()          bzPushMatrix()
70 #    define glPopMatrix()           bzPopMatrix()
71 #    define glMatrixMode(mode)          bzMatrixMode(mode)
72 #  endif // DEBUG_GL_MATRIX_STACKS
73 #endif
74 // always swap these calls (context protection)
75 #define glDeleteLists(base, count)      bzDeleteLists((base), (count))
76 #define glDeleteTextures(count, textures)   bzDeleteTextures((count), (textures))
77 
78 // these are housed at the end of OpenGLGState.cxx, for now
79 extern void   bzNewList(GLuint list, GLenum mode);
80 extern GLuint bzGenLists(GLsizei count);
81 extern void   bzGenTextures(GLsizei count, GLuint *textures);
82 extern void   bzDeleteLists(GLuint base, GLsizei count);
83 extern void   bzDeleteTextures(GLsizei count, const GLuint *textures);
84 extern void   bzPushMatrix();
85 extern void   bzPopMatrix();
86 extern void   bzMatrixMode(GLenum mode);
87 
88 
89 #endif /* __BZFGL_H__ */
90 
91 // Local Variables: ***
92 // mode: C++ ***
93 // tab-width: 4 ***
94 // c-basic-offset: 4 ***
95 // indent-tabs-mode: nil ***
96 // End: ***
97 // ex: shiftwidth=4 tabstop=4
98