1import sys
2
3
4def fs_emu_blending(enable):
5    if enable:
6        gl.glEnable(gl.GL_BLEND)
7    else:
8        gl.glDisable(gl.GL_BLEND)
9
10
11def fs_emu_texturing(enable):
12    if enable:
13        gl.glEnable(gl.GL_TEXTURE_2D)
14    else:
15        gl.glDisable(gl.GL_TEXTURE_2D)
16
17
18class GL:
19    # These constants are repeated here to aid code inspection tools (in
20    # PyOpenGL they are expanded (run-time) from a string).
21
22    GL_BLEND = 0xBE2
23    GL_TEXTURE_2D = 0xDE1
24    GL_COMPILE_STATUS = 0x8B81
25    GL_LINK_STATUS = 0x8B82
26    GL_FRAGMENT_SHADER = 0x8B30
27    GL_VERTEX_SHADER = 0x8B31
28    GL_ONE = 0x1
29    GL_ONE_MINUS_SRC_COLOR = 0x301
30    GL_SRC_ALPHA = 0x302
31    GL_ONE_MINUS_SRC_ALPHA = 0x303
32    GL_RGB = 0x1907
33    GL_RGBA = 0x1908
34    GL_BGRA = 0x80E1
35    GL_TEXTURE_MAG_FILTER = 0x2800
36    GL_TEXTURE_MIN_FILTER = 0x2801
37    GL_FRAMEBUFFER_EXT = 0x8D40
38    GL_COLOR_ATTACHMENT0_EXT = 0x8CE0
39    GL_RENDERBUFFER_EXT = 0x8D41
40    GL_DEPTH_ATTACHMENT_EXT = 0x8D00
41    GL_LINEAR = 0x2601
42    GL_FRAMEBUFFER_COMPLETE_EXT = 0x8CD5
43    GL_DEPTH_COMPONENT24 = 0x81A6
44    GL_QUADS = 0x7
45    GL_DEPTH_TEST = 0xB71
46    GL_TEXTURE_2D_ARB = 0x207A
47    GL_COLOR_BUFFER_BIT = 0x4000
48    GL_DEPTH_BUFFER_BIT = 0x100
49    GL_MODELVIEW = 0x1700
50    GL_PROJECTION = 0x1701
51    GL_LIGHT_MODEL_TWO_SIDE = 0xB52
52    GL_LIGHT_MODEL_LOCAL_VIEWER = 0xB51
53    GL_LIGHT_MODEL_AMBIENT = 0xB53
54    GL_SEPARATE_SPECULAR_COLOR = 0x81FA
55    GL_LIGHT_MODEL_COLOR_CONTROL = 0x81F8
56    GL_LIGHTING = 0xB50
57    GL_LIGHT0 = 0x4000
58    GL_LIGHT1 = 0x4001
59    GL_LIGHT2 = 0x4002
60    GL_LIGHT3 = 0x4003
61    GL_LIGHT4 = 0x4004
62    GL_LIGHT5 = 0x4005
63    GL_LIGHT6 = 0x4006
64    GL_LIGHT7 = 0x4007
65    GL_AMBIENT = 0x1200
66    GL_DIFFUSE = 0x1201
67    GL_SPECULAR = 0x1202
68    GL_SHININESS = 0x1601
69    GL_EMISSION = 0x1600
70    GL_POSITION = 0x1203
71    GL_FRONT = 0x404
72    GL_BACK = 0x405
73    GL_POLYGON_OFFSET_FILL = 0x8037
74    GL_CLAMP_TO_EDGE = 0x812F
75
76    def __init__(self):
77        self._loaded = False
78        self._first_time = True
79
80    def load(self):
81        if self._loaded:
82            return
83        if self._first_time:
84            import locale
85
86            # we must set the LC_NUMERIC locale to C, because PyOpenGL has
87            # a problem if comma is used as a decimal separator (problem
88            # parsing the OpenGL version)
89            locale.setlocale(locale.LC_NUMERIC, str("C"))
90        from .pyopengl import pyopengl_globals, filter_global
91
92        for name in list(pyopengl_globals()):
93            if filter_global(name):
94                setattr(gl, name, pyopengl_globals()[name])
95        if self._first_time:
96            self.log_opengl_info()
97        self._loaded = True
98        self._first_time = False
99
100    def unload(self):
101        for name in list(self.__dict__.keys()):
102            if name.lower().startswith("gl"):
103                delattr(self, name)
104        self._loaded = False
105
106    def log_opengl_info(self):
107        print("[OPENGL] PyOpenGL information:")
108        print("[OPENGL]", sys.modules["OpenGL"])
109        print("[OPENGL] Vendor:", self.glGetString(self.GL_VENDOR))
110        print("[OPENGL] Renderer:", self.glGetString(self.GL_RENDERER))
111        print("[OPENGL] Version:", self.glGetString(self.GL_VERSION))
112
113
114gl = GL()
115
116# for __x in list(globals()):
117#     if filter_global(__x):
118#         setattr(gl, __x, globals()[__x])
119
120
121if False:
122    # this fixes ImportError: No module named win32 when used with py2exe
123    # and other problems related to required modules missing from pyOpenGL
124    # noinspection PyUnresolvedReferences
125    import ctypes
126
127    # noinspection PyUnresolvedReferences
128    import logging
129
130    # noinspection PyUnresolvedReferences
131    import OpenGL.platform.win32
132
133    # noinspection PyUnresolvedReferences
134    import OpenGL.arrays._buffers
135
136    # noinspection PyUnresolvedReferences
137    import OpenGL.arrays._numeric
138
139    # noinspection PyUnresolvedReferences
140    import OpenGL.arrays._strings
141
142    # noinspection PyUnresolvedReferences
143    import OpenGL.arrays.arraydatatype
144
145    # noinspection PyUnresolvedReferences
146    import OpenGL.arrays.arrayhelpers
147
148    # noinspection PyUnresolvedReferences
149    import OpenGL.arrays.buffers
150
151    # noinspection PyUnresolvedReferences
152    import OpenGL.arrays.ctypesarrays
153
154    # noinspection PyUnresolvedReferences
155    import OpenGL.arrays.ctypesparameters
156
157    # noinspection PyUnresolvedReferences
158    import OpenGL.arrays.ctypespointers
159
160    # noinspection PyUnresolvedReferences
161    import OpenGL.arrays.formathandler
162
163    # noinspection PyUnresolvedReferences
164    import OpenGL.arrays.lists
165
166    # noinspection PyUnresolvedReferences
167    import OpenGL.arrays.nones
168
169    # noinspection PyUnresolvedReferences
170    import OpenGL.arrays.numbers
171
172    # noinspection PyUnresolvedReferences
173    import OpenGL.arrays.numeric
174
175    # noinspection PyUnresolvedReferences
176    import OpenGL.arrays.numericnames
177
178    # noinspection PyUnresolvedReferences
179    # import OpenGL.arrays.numpymodule
180    # noinspection PyUnresolvedReferences
181    import OpenGL.arrays.strings
182
183    # noinspection PyUnresolvedReferences
184    import OpenGL.arrays.vbo
185