comparison pytouhou/ui/gamerenderer.pyx @ 424:f4d76d3d6f2a

Make the Shader class use cython too.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 16 Jul 2013 21:07:15 +0200
parents d8630c086926
children 0604f4fbbe3c
comparison
equal deleted inserted replaced
423:d8630c086926 424:f4d76d3d6f2a
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15
16 from libc.stdlib cimport malloc, free 15 from libc.stdlib cimport malloc, free
17
18 from itertools import chain 16 from itertools import chain
19 17
20 from pytouhou.lib.opengl cimport \ 18 from pytouhou.lib.opengl cimport \
21 (glClear, glMatrixMode, glLoadIdentity, glLoadMatrixf, glDisable, 19 (glClear, glMatrixMode, glLoadIdentity, glLoadMatrixf, glDisable,
22 glEnable, glFogi, glFogf, glFogfv, GL_DEPTH_BUFFER_BIT, 20 glEnable, glFogi, glFogf, glFogfv, GL_DEPTH_BUFFER_BIT,
52 glMatrixMode(GL_MODELVIEW) 50 glMatrixMode(GL_MODELVIEW)
53 glLoadMatrixf(matrix_to_floats(self.game_mvp)) 51 glLoadMatrixf(matrix_to_floats(self.game_mvp))
54 glDisable(GL_FOG) 52 glDisable(GL_FOG)
55 else: 53 else:
56 self.game_shader.bind() 54 self.game_shader.bind()
57 self.game_shader.uniform_matrixf('mvp', self.game_mvp.get_c_data()) 55 self.game_shader.uniform_matrix('mvp', self.game_mvp)
58 56
59 self.render_elements([game.spellcard_effect]) 57 self.render_elements([game.spellcard_effect])
60 elif back is not None: 58 elif back is not None:
61 x, y, z = back.position_interpolator.values 59 x, y, z = back.position_interpolator.values
62 dx, dy, dz = back.position2_interpolator.values 60 dx, dy, dz = back.position2_interpolator.values
72 fog_end -= 101010101./2010101. 70 fog_end -= 101010101./2010101.
73 71
74 model = Matrix() 72 model = Matrix()
75 model.data[3] = [-x, -y, -z, 1] 73 model.data[3] = [-x, -y, -z, 1]
76 view = setup_camera(dx, dy, dz) 74 view = setup_camera(dx, dy, dz)
77 model_view_projection = model * view * self.proj 75 mvp = model * view * self.proj
78 mvp = model_view_projection.get_c_data()
79 mvp_cython = matrix_to_floats(model_view_projection)
80 76
81 if self.use_fixed_pipeline: 77 if self.use_fixed_pipeline:
82 glMatrixMode(GL_MODELVIEW) 78 glMatrixMode(GL_MODELVIEW)
83 glLoadMatrixf(mvp_cython) 79 glLoadMatrixf(matrix_to_floats(mvp))
84 80
85 glEnable(GL_FOG) 81 glEnable(GL_FOG)
86 glFogi(GL_FOG_MODE, GL_LINEAR) 82 glFogi(GL_FOG_MODE, GL_LINEAR)
87 glFogf(GL_FOG_START, fog_start) 83 glFogf(GL_FOG_START, fog_start)
88 glFogf(GL_FOG_END, fog_end) 84 glFogf(GL_FOG_END, fog_end)
85
89 fog_data = <float*>malloc(4 * sizeof(float)) 86 fog_data = <float*>malloc(4 * sizeof(float))
90 fog_data[0] = fog_r / 255. 87 fog_data[0] = fog_r / 255.
91 fog_data[1] = fog_g / 255. 88 fog_data[1] = fog_g / 255.
92 fog_data[2] = fog_b / 255. 89 fog_data[2] = fog_b / 255.
93 fog_data[3] = 1. 90 fog_data[3] = 1.
94 glFogfv(GL_FOG_COLOR, fog_data) 91 glFogfv(GL_FOG_COLOR, fog_data)
95 free(fog_data) 92 free(fog_data)
96 else: 93 else:
97 self.background_shader.bind() 94 self.background_shader.bind()
98 self.background_shader.uniform_matrixf('mvp', mvp) 95 self.background_shader.uniform_matrix('mvp', mvp)
99 96
100 self.background_shader.uniformf('fog_scale', 1. / (fog_end - fog_start)) 97 self.background_shader.uniform_1('fog_scale', 1. / (fog_end - fog_start))
101 self.background_shader.uniformf('fog_end', fog_end) 98 self.background_shader.uniform_1('fog_end', fog_end)
102 self.background_shader.uniformf('fog_color', fog_r / 255., fog_g / 255., fog_b / 255., 1.) 99 self.background_shader.uniform_4('fog_color', fog_r / 255., fog_g / 255., fog_b / 255., 1.)
103 100
104 self.background_renderer.render_background() 101 self.background_renderer.render_background()
105 else: 102 else:
106 glClear(GL_COLOR_BUFFER_BIT) 103 glClear(GL_COLOR_BUFFER_BIT)
107 104
110 glMatrixMode(GL_MODELVIEW) 107 glMatrixMode(GL_MODELVIEW)
111 glLoadMatrixf(matrix_to_floats(self.game_mvp)) 108 glLoadMatrixf(matrix_to_floats(self.game_mvp))
112 glDisable(GL_FOG) 109 glDisable(GL_FOG)
113 else: 110 else:
114 self.game_shader.bind() 111 self.game_shader.bind()
115 self.game_shader.uniform_matrixf('mvp', self.game_mvp.get_c_data()) 112 self.game_shader.uniform_matrix('mvp', self.game_mvp)
116 113
117 self.render_elements(enemy for enemy in game.enemies if enemy.visible) 114 self.render_elements(enemy for enemy in game.enemies if enemy.visible)
118 self.render_elements(game.effects) 115 self.render_elements(game.effects)
119 self.render_elements(chain(game.players_bullets, 116 self.render_elements(chain(game.players_bullets,
120 game.lasers_sprites(), 117 game.lasers_sprites(),