comparison pytouhou/ui/renderer.pyx @ 398:8d252cdb495f

Move the background rendering code to pytouhou.ui.renderer.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 12 Feb 2013 18:20:49 +0100
parents c5ba11ede097
children 1c773544eaeb
comparison
equal deleted inserted replaced
397:c5ba11ede097 398:8d252cdb495f
25 glVertexAttribPointer, glEnableVertexAttribArray, 25 glVertexAttribPointer, glEnableVertexAttribArray,
26 glBlendFunc, glBindTexture, glDrawElements, 26 glBlendFunc, glBindTexture, glDrawElements,
27 glBindBuffer, glBufferData, GL_ARRAY_BUFFER, 27 glBindBuffer, glBufferData, GL_ARRAY_BUFFER,
28 GL_DYNAMIC_DRAW, GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, 28 GL_DYNAMIC_DRAW, GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT,
29 GL_INT, GL_FLOAT, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 29 GL_INT, GL_FLOAT, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
30 GL_ONE, GL_TEXTURE_2D, GL_TRIANGLES) 30 GL_ONE, GL_TEXTURE_2D, GL_TRIANGLES,
31 glEnable, glDisable, GL_DEPTH_TEST, glDrawArrays, GL_QUADS)
31 32
32 from .sprite cimport get_sprite_rendering_data 33 from .sprite cimport get_sprite_rendering_data
34 from .background import get_background_rendering_data
33 from .texture cimport TextureManager 35 from .texture cimport TextureManager
34 from pytouhou.utils.matrix cimport Matrix 36 from pytouhou.utils.matrix cimport Matrix
35 from pytouhou.utils.vector import Vector, normalize, cross, dot 37 from pytouhou.utils.vector import Vector, normalize, cross, dot
36 38
37 39
108 110
109 if not self.use_fixed_pipeline: 111 if not self.use_fixed_pipeline:
110 glBindBuffer(GL_ARRAY_BUFFER, 0) 112 glBindBuffer(GL_ARRAY_BUFFER, 0)
111 113
112 114
115 cpdef render_background(self, back):
116 glEnable(GL_DEPTH_TEST)
117 for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back):
118 if self.use_fixed_pipeline:
119 glVertexPointer(3, GL_FLOAT, 0, vertices)
120 glTexCoordPointer(2, GL_FLOAT, 0, uvs)
121 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors)
122 else:
123 glVertexAttribPointer(0, 3, GL_FLOAT, False, 0, vertices)
124 glEnableVertexAttribArray(0)
125 glVertexAttribPointer(1, 2, GL_FLOAT, False, 0, uvs)
126 glEnableVertexAttribArray(1)
127 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, 0, colors)
128 glEnableVertexAttribArray(2)
129 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
130 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key])
131 glDrawArrays(GL_QUADS, 0, nb_vertices)
132 glDisable(GL_DEPTH_TEST)
133
134
113 cpdef ortho_2d(self, left, right, bottom, top): 135 cpdef ortho_2d(self, left, right, bottom, top):
114 mat = Matrix() 136 mat = Matrix()
115 mat[0][0] = 2 / (right - left) 137 mat[0][0] = 2 / (right - left)
116 mat[1][1] = 2 / (top - bottom) 138 mat[1][1] = 2 / (top - bottom)
117 mat[2][2] = -1 139 mat[2][2] = -1