comparison pytouhou/opengl/gamerenderer.py @ 126:9d7129ee2c4f

Fix a rendering bug
author Thibaut Girka <thib@sitedethib.com>
date Sat, 10 Sep 2011 15:35:18 +0200
parents 0313ca2c50e9
children 11ab06f4c4c6
comparison
equal deleted inserted replaced
125:0313ca2c50e9 126:9d7129ee2c4f
100 for element in elements: 100 for element in elements:
101 sprite = element._sprite 101 sprite = element._sprite
102 if sprite: 102 if sprite:
103 ox, oy = element.x, element.y 103 ox, oy = element.x, element.y
104 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite) 104 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite)
105 rec = indices_by_texture.setdefault(key, [0, []]) 105 rec = indices_by_texture.setdefault(key, [])
106 index = rec[0]
107 106
108 # Pack data in buffer 107 # Pack data in buffer
109 (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4) = vertices 108 (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4) = vertices
110 r1, g1, b1, a1, r2, g2, b2, a2, r3, g3, b3, a3, r4, g4, b4, a4 = colors 109 r1, g1, b1, a1, r2, g2, b2, a2, r3, g3, b3, a3, r4, g4, b4, a4 = colors
111 u1, v1, u2, v2, u3, v3, u4, v4 = uvs 110 u1, v1, u2, v2, u3, v3, u4, v4 = uvs
125 x4 + ox, y4 + oy, z4, 124 x4 + ox, y4 + oy, z4,
126 u4, v4, 125 u4, v4,
127 r4, g4, b4, a4) 126 r4, g4, b4, a4)
128 127
129 # Add indices 128 # Add indices
130 rec[0] += 4 129 index = nb_vertices
131 rec[1].extend((index, index + 1, index + 2, index + 3)) 130 rec.extend((index, index + 1, index + 2, index + 3))
132 131
133 nb_vertices += 4 132 nb_vertices += 4
134 133
135 glVertexPointer(3, GL_FLOAT, 24, _vertices) 134 glVertexPointer(3, GL_FLOAT, 24, _vertices)
136 glTexCoordPointer(2, GL_FLOAT, 24, _uvs) 135 glTexCoordPointer(2, GL_FLOAT, 24, _uvs)
137 glColorPointer(4, GL_UNSIGNED_BYTE, 24, _colors) 136 glColorPointer(4, GL_UNSIGNED_BYTE, 24, _colors)
138 137
139 for (texture_key, blendfunc), (nb_indices, indices) in indices_by_texture.items(): 138 for (texture_key, blendfunc), indices in indices_by_texture.items():
139 nb_indices = len(indices)
140 indices = struct.pack(str(nb_indices) + 'H', *indices) 140 indices = struct.pack(str(nb_indices) + 'H', *indices)
141 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) 141 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
142 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key].id) 142 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key].id)
143 glDrawElements(GL_QUADS, nb_indices, GL_UNSIGNED_SHORT, indices) 143 glDrawElements(GL_QUADS, nb_indices, GL_UNSIGNED_SHORT, indices)
144 144