Mercurial > touhou
changeset 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 |
files | pytouhou/ui/gamerenderer.py pytouhou/ui/renderer.pxd pytouhou/ui/renderer.pyx |
diffstat | 3 files changed, 26 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/ui/gamerenderer.py +++ b/pytouhou/ui/gamerenderer.py @@ -17,20 +17,13 @@ from itertools import chain from pyglet.gl import (glClear, glMatrixMode, glLoadIdentity, glLoadMatrixf, glDisable, glEnable, glFogi, glFogf, glFogfv, - glBlendFunc, glBindTexture, glVertexPointer, - glTexCoordPointer, glColorPointer, glDrawArrays, - glVertexAttribPointer, glEnableVertexAttribArray, GL_DEPTH_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW, GL_FOG, GL_FOG_MODE, GL_LINEAR, GL_FOG_START, - GL_FOG_END, GL_FOG_COLOR, GL_DEPTH_TEST, GL_SRC_ALPHA, - GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_TEXTURE_2D, - GL_UNSIGNED_BYTE, GL_FLOAT, GL_QUADS, - GL_COLOR_BUFFER_BIT, GLfloat) + GL_FOG_END, GL_FOG_COLOR, GL_COLOR_BUFFER_BIT, GLfloat) from pytouhou.utils.matrix import Matrix from .renderer import Renderer -from .background import get_background_rendering_data @@ -57,7 +50,6 @@ class GameRenderer(Renderer): back = self.background game = self.game - texture_manager = self.texture_manager if self.use_fixed_pipeline: glMatrixMode(GL_PROJECTION) @@ -100,23 +92,7 @@ class GameRenderer(Renderer): self.background_shader.uniform_matrixf('model_view', model_view.get_c_data()) self.background_shader.uniform_matrixf('projection', self.proj.get_c_data()) - glEnable(GL_DEPTH_TEST) - for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back): - glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) - glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) - if self.use_fixed_pipeline: - glVertexPointer(3, GL_FLOAT, 0, vertices) - glTexCoordPointer(2, GL_FLOAT, 0, uvs) - glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors) - else: - glVertexAttribPointer(0, 3, GL_FLOAT, False, 0, vertices) - glEnableVertexAttribArray(0) - glVertexAttribPointer(1, 2, GL_FLOAT, False, 0, uvs) - glEnableVertexAttribArray(1) - glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, 0, colors) - glEnableVertexAttribArray(2) - glDrawArrays(GL_QUADS, 0, nb_vertices) - glDisable(GL_DEPTH_TEST) + self.render_background(back) else: glClear(GL_COLOR_BUFFER_BIT) @@ -138,4 +114,3 @@ class GameRenderer(Renderer): self.render_elements(chain(game.bullets, game.lasers, game.cancelled_bullets, game.items, game.labels)) -
--- a/pytouhou/ui/renderer.pxd +++ b/pytouhou/ui/renderer.pxd @@ -9,6 +9,7 @@ cdef class Renderer: cdef Vertex *vertex_buffer cpdef render_elements(self, elements) + cpdef render_background(self, back) cpdef ortho_2d(self, left, right, bottom, top) cpdef look_at(self, eye, center, up) cpdef perspective(self, fovy, aspect, zNear, zFar)
--- a/pytouhou/ui/renderer.pyx +++ b/pytouhou/ui/renderer.pyx @@ -27,9 +27,11 @@ from pyglet.gl import (glVertexPointer, glBindBuffer, glBufferData, GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW, GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_INT, GL_FLOAT, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, - GL_ONE, GL_TEXTURE_2D, GL_TRIANGLES) + GL_ONE, GL_TEXTURE_2D, GL_TRIANGLES, + glEnable, glDisable, GL_DEPTH_TEST, glDrawArrays, GL_QUADS) from .sprite cimport get_sprite_rendering_data +from .background import get_background_rendering_data from .texture cimport TextureManager from pytouhou.utils.matrix cimport Matrix from pytouhou.utils.vector import Vector, normalize, cross, dot @@ -110,6 +112,26 @@ cdef class Renderer: glBindBuffer(GL_ARRAY_BUFFER, 0) + cpdef render_background(self, back): + glEnable(GL_DEPTH_TEST) + for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back): + if self.use_fixed_pipeline: + glVertexPointer(3, GL_FLOAT, 0, vertices) + glTexCoordPointer(2, GL_FLOAT, 0, uvs) + glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors) + else: + glVertexAttribPointer(0, 3, GL_FLOAT, False, 0, vertices) + glEnableVertexAttribArray(0) + glVertexAttribPointer(1, 2, GL_FLOAT, False, 0, uvs) + glEnableVertexAttribArray(1) + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, 0, colors) + glEnableVertexAttribArray(2) + glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) + glBindTexture(GL_TEXTURE_2D, self.texture_manager[texture_key]) + glDrawArrays(GL_QUADS, 0, nb_vertices) + glDisable(GL_DEPTH_TEST) + + cpdef ortho_2d(self, left, right, bottom, top): mat = Matrix() mat[0][0] = 2 / (right - left)