Mercurial > touhou
comparison pytouhou/ui/gamerenderer.py @ 394:346614f788f1
Replace gl{Vertex,TexCoord,Color}Pointer with the more modern glVertexAttribPointer.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 06 Feb 2013 20:57:16 +0100 |
parents | 9e2cbb2c2c64 |
children | 8d252cdb495f |
comparison
equal
deleted
inserted
replaced
393:9e2cbb2c2c64 | 394:346614f788f1 |
---|---|
17 | 17 |
18 from pyglet.gl import (glClear, glMatrixMode, glLoadIdentity, glLoadMatrixf, | 18 from pyglet.gl import (glClear, glMatrixMode, glLoadIdentity, glLoadMatrixf, |
19 glDisable, glEnable, glFogi, glFogf, glFogfv, | 19 glDisable, glEnable, glFogi, glFogf, glFogfv, |
20 glBlendFunc, glBindTexture, glVertexPointer, | 20 glBlendFunc, glBindTexture, glVertexPointer, |
21 glTexCoordPointer, glColorPointer, glDrawArrays, | 21 glTexCoordPointer, glColorPointer, glDrawArrays, |
22 glVertexAttribPointer, glEnableVertexAttribArray, | |
22 GL_DEPTH_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW, | 23 GL_DEPTH_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW, |
23 GL_FOG, GL_FOG_MODE, GL_LINEAR, GL_FOG_START, | 24 GL_FOG, GL_FOG_MODE, GL_LINEAR, GL_FOG_START, |
24 GL_FOG_END, GL_FOG_COLOR, GL_DEPTH_TEST, GL_SRC_ALPHA, | 25 GL_FOG_END, GL_FOG_COLOR, GL_DEPTH_TEST, GL_SRC_ALPHA, |
25 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, | 26 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, |
26 GL_UNSIGNED_BYTE, GL_FLOAT, GL_QUADS, | 27 GL_UNSIGNED_BYTE, GL_FLOAT, GL_QUADS, |
87 glFogfv(GL_FOG_COLOR, (GLfloat * 4)(fog_r / 255., fog_g / 255., fog_b / 255., 1.)) | 88 glFogfv(GL_FOG_COLOR, (GLfloat * 4)(fog_r / 255., fog_g / 255., fog_b / 255., 1.)) |
88 | 89 |
89 model = Matrix() | 90 model = Matrix() |
90 model.data[3] = [-x, -y, -z, 1] | 91 model.data[3] = [-x, -y, -z, 1] |
91 view = self.setup_camera(dx, dy, dz) | 92 view = self.setup_camera(dx, dy, dz) |
92 model_view = model * view | |
93 model_view_projection = model * view * self.proj | |
94 | 93 |
95 if self.use_fixed_pipeline: | 94 if self.use_fixed_pipeline: |
95 model_view_projection = model * view * self.proj | |
96 glMatrixMode(GL_MODELVIEW) | 96 glMatrixMode(GL_MODELVIEW) |
97 glLoadMatrixf(model_view_projection.get_c_data()) | 97 glLoadMatrixf(model_view_projection.get_c_data()) |
98 else: | 98 else: |
99 model_view = model * view | |
99 self.background_shader.uniform_matrixf('model_view', model_view.get_c_data()) | 100 self.background_shader.uniform_matrixf('model_view', model_view.get_c_data()) |
100 self.background_shader.uniform_matrixf('projection', self.proj.get_c_data()) | 101 self.background_shader.uniform_matrixf('projection', self.proj.get_c_data()) |
101 | 102 |
102 glEnable(GL_DEPTH_TEST) | 103 glEnable(GL_DEPTH_TEST) |
103 for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back): | 104 for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back): |
104 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) | 105 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) |
105 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) | 106 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) |
106 glVertexPointer(3, GL_FLOAT, 0, vertices) | 107 if self.use_fixed_pipeline: |
107 glTexCoordPointer(2, GL_FLOAT, 0, uvs) | 108 glVertexPointer(3, GL_FLOAT, 0, vertices) |
108 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors) | 109 glTexCoordPointer(2, GL_FLOAT, 0, uvs) |
110 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors) | |
111 else: | |
112 glVertexAttribPointer(0, 3, GL_FLOAT, False, 0, vertices) | |
113 glEnableVertexAttribArray(0) | |
114 glVertexAttribPointer(1, 2, GL_FLOAT, False, 0, uvs) | |
115 glEnableVertexAttribArray(1) | |
116 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, 0, colors) | |
117 glEnableVertexAttribArray(2) | |
109 glDrawArrays(GL_QUADS, 0, nb_vertices) | 118 glDrawArrays(GL_QUADS, 0, nb_vertices) |
110 glDisable(GL_DEPTH_TEST) | 119 glDisable(GL_DEPTH_TEST) |
111 else: | 120 else: |
112 glClear(GL_COLOR_BUFFER_BIT) | 121 glClear(GL_COLOR_BUFFER_BIT) |
113 | 122 |