comparison pytouhou/ui/renderer.pyx @ 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 43413d4ff05b
comparison
equal deleted inserted replaced
393:9e2cbb2c2c64 394:346614f788f1
20 import ctypes 20 import ctypes
21 21
22 from struct import pack 22 from struct import pack
23 23
24 from pyglet.gl import (glVertexPointer, glTexCoordPointer, glColorPointer, 24 from pyglet.gl import (glVertexPointer, glTexCoordPointer, glColorPointer,
25 glVertexAttribPointer, glEnableVertexAttribArray,
25 glBlendFunc, glBindTexture, glDrawElements, 26 glBlendFunc, glBindTexture, glDrawElements,
26 GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_INT, GL_FLOAT, 27 GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_INT, GL_FLOAT,
27 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, 28 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE,
28 GL_TEXTURE_2D, GL_TRIANGLES) 29 GL_TEXTURE_2D, GL_TRIANGLES)
29 30
80 rec.extend((index, index + 1, index + 2, index + 2, index + 3, index)) 81 rec.extend((index, index + 1, index + 2, index + 2, index + 3, index))
81 82
82 nb_vertices += 4 83 nb_vertices += 4
83 84
84 for (texture_key, blendfunc), indices in indices_by_texture.items(): 85 for (texture_key, blendfunc), indices in indices_by_texture.items():
85 glVertexPointer(3, GL_INT, 24, <long> &self.vertex_buffer[0].x) 86 if self.use_fixed_pipeline:
86 glTexCoordPointer(2, GL_FLOAT, 24, <long> &self.vertex_buffer[0].u) 87 glVertexPointer(3, GL_INT, sizeof(Vertex), <long> &self.vertex_buffer[0].x)
87 glColorPointer(4, GL_UNSIGNED_BYTE, 24, <long> &self.vertex_buffer[0].r) 88 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), <long> &self.vertex_buffer[0].u)
89 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), <long> &self.vertex_buffer[0].r)
90 else:
91 glVertexAttribPointer(0, 3, GL_INT, False, sizeof(Vertex), <long> &self.vertex_buffer[0].x)
92 glEnableVertexAttribArray(0)
93 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <long> &self.vertex_buffer[0].u)
94 glEnableVertexAttribArray(1)
95 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <long> &self.vertex_buffer[0].r)
96 glEnableVertexAttribArray(2)
88 97
89 nb_indices = len(indices) 98 nb_indices = len(indices)
90 indices = pack(str(nb_indices) + 'H', *indices) 99 indices = pack(str(nb_indices) + 'H', *indices)
91 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) 100 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
92 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key]) 101 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key])