comparison pytouhou/opengl/gamerenderer.pyx @ 201:220c122f428c

Batch more sprites!
author Thibaut Girka <thib@sitedethib.com>
date Mon, 31 Oct 2011 18:08:26 +0100
parents 8ec34c56fed0
children
comparison
equal deleted inserted replaced
200:300661f2ae8a 201:220c122f428c
14 14
15 from libc.stdlib cimport malloc, free 15 from libc.stdlib cimport malloc, free
16 16
17 import ctypes 17 import ctypes
18 18
19 import struct 19 from struct import pack
20 from itertools import chain
20 21
21 from pyglet.gl import * 22 from pyglet.gl import *
22 23
23 from pytouhou.opengl.texture import TextureManager 24 from pytouhou.opengl.texture import TextureManager
24 from pytouhou.opengl.sprite cimport get_sprite_rendering_data 25 from pytouhou.opengl.sprite cimport get_sprite_rendering_data
89 glVertexPointer(3, GL_INT, 24, <long> &self.vertex_buffer[0].x) 90 glVertexPointer(3, GL_INT, 24, <long> &self.vertex_buffer[0].x)
90 glTexCoordPointer(2, GL_FLOAT, 24, <long> &self.vertex_buffer[0].u) 91 glTexCoordPointer(2, GL_FLOAT, 24, <long> &self.vertex_buffer[0].u)
91 glColorPointer(4, GL_UNSIGNED_BYTE, 24, <long> &self.vertex_buffer[0].r) 92 glColorPointer(4, GL_UNSIGNED_BYTE, 24, <long> &self.vertex_buffer[0].r)
92 93
93 nb_indices = len(indices) 94 nb_indices = len(indices)
94 indices = struct.pack(str(nb_indices) + 'H', *indices) 95 indices = pack(str(nb_indices) + 'H', *indices)
95 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) 96 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
96 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key].id) 97 glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key].id)
97 glDrawElements(GL_QUADS, nb_indices, GL_UNSIGNED_SHORT, indices) 98 glDrawElements(GL_QUADS, nb_indices, GL_UNSIGNED_SHORT, indices)
98 99
99 100
149 192., 224., 0., 0., -1., 0.) 150 192., 224., 0., 0., -1., 0.)
150 151
151 glDisable(GL_FOG) 152 glDisable(GL_FOG)
152 self.render_elements(game.enemies) 153 self.render_elements(game.enemies)
153 self.render_elements(game.effects) 154 self.render_elements(game.effects)
154 self.render_elements(game.players) 155 self.render_elements(chain(game.players_bullets,
155 for player in game.players: 156 game.players,
156 self.render_elements(player.objects()) 157 *(player.objects() for player in game.players)))
157 self.render_elements(game.bullets) 158 self.render_elements(chain(game.bullets, game.cancelled_bullets, game.items))
158 self.render_elements(game.cancelled_bullets)
159 self.render_elements(game.players_bullets)
160 self.render_elements(game.items)
161 #TODO: display item indicators 159 #TODO: display item indicators
162 glEnable(GL_FOG) 160 glEnable(GL_FOG)
163 161