Mercurial > touhou
annotate pytouhou/ui/gamerenderer.pyx @ 508:1bc014f9d572
Make GameRunner entirely independent of Window or GameRenderer, so we can run a game without display.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 19 Nov 2013 14:19:14 +0100 |
parents | bfea9e9a6845 |
children | 2e8ceaa85d5c |
rev | line source |
---|---|
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 |
201 | 15 from itertools import chain |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
130
diff
changeset
|
16 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
17 from pytouhou.lib.opengl cimport \ |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
18 (glClear, glMatrixMode, glLoadIdentity, glLoadMatrixf, glDisable, |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
19 glEnable, glFogi, glFogf, glFogfv, GL_PROJECTION, GL_MODELVIEW, |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
20 GL_FOG, GL_FOG_MODE, GL_LINEAR, GL_FOG_START, GL_FOG_END, |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
21 GL_FOG_COLOR, GL_COLOR_BUFFER_BIT, GLfloat, glViewport, glScissor, |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
22 GL_SCISSOR_TEST, GL_DEPTH_BUFFER_BIT) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
23 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
24 from pytouhou.utils.maths cimport perspective, setup_camera, ortho_2d |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
25 from pytouhou.game.text cimport NativeText, GlyphCollection |
462
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
26 from .shaders.eosd import GameShader, BackgroundShader, PassthroughShader |
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
503
diff
changeset
|
27 from .renderer cimport Texture |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
28 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
29 from collections import namedtuple |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
30 Rect = namedtuple('Rect', 'x y w h') |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
31 Color = namedtuple('Color', 'r g b a') |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
32 |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
33 |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
34 cdef class GameRenderer(Renderer): |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
35 def __init__(self, resource_loader, use_fixed_pipeline): |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
36 self.use_fixed_pipeline = use_fixed_pipeline #XXX |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
37 |
222
5cac48b328ad
Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
221
diff
changeset
|
38 Renderer.__init__(self, resource_loader) |
254
6bd565019f9a
Preload textures to avoid slowdowns during gameplay
Thibaut Girka <thib@sitedethib.com>
parents:
242
diff
changeset
|
39 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
40 if not self.use_fixed_pipeline: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
41 self.game_shader = GameShader() |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
42 self.background_shader = BackgroundShader() |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
43 self.interface_shader = self.game_shader |
462
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
44 self.passthrough_shader = PassthroughShader() |
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
45 |
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
46 self.framebuffer = Framebuffer(0, 0, 640, 480) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
47 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
48 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
49 cdef void load_background(self, background): |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
50 if background is not None: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
51 self.background_renderer = BackgroundRenderer(self.use_fixed_pipeline) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
52 self.background_renderer.load(background) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
53 else: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
54 self.background_renderer = None |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
55 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
56 |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
57 cdef void start(self, common): |
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
58 self.proj = perspective(30, float(common.width) / float(common.height), |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
59 101010101./2010101., 101010101./10101.) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
60 game_view = setup_camera(0, 0, 1) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
61 self.game_mvp = game_view * self.proj |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
62 self.interface_mvp = ortho_2d(0., float(common.interface.width), |
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
63 float(common.interface.height), 0.) |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
64 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
65 |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
66 cdef void render(self, Game game): |
462
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
67 if not self.use_fixed_pipeline: |
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
68 self.framebuffer.bind() |
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
69 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
70 self.render_game(game) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
71 self.render_text(game.texts + game.native_texts) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
72 self.render_interface(game.interface, game.boss) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
73 |
462
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
74 if not self.use_fixed_pipeline: |
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
75 self.passthrough_shader.bind() |
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
76 self.passthrough_shader.uniform_matrix('mvp', self.interface_mvp) |
503
c622eaf64428
Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
77 self.render_framebuffer(self.framebuffer) |
462
a71b912b45b7
Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
459
diff
changeset
|
78 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
79 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
464
diff
changeset
|
80 cdef void render_game(self, Game game): |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
81 cdef long game_x, game_y |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
82 cdef float x, y, z, dx, dy, dz, fog_data[4], fog_start, fog_end |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
83 cdef unsigned char fog_r, fog_g, fog_b |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
84 cdef Matrix mvp |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
85 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
86 game_x, game_y = game.interface.game_pos |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
87 glViewport(game_x, game_y, game.width, game.height) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
88 glClear(GL_DEPTH_BUFFER_BIT) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
89 glScissor(game_x, game_y, game.width, game.height) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
90 glEnable(GL_SCISSOR_TEST) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
91 |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
92 if self.use_fixed_pipeline: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
93 glMatrixMode(GL_PROJECTION) |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
94 glLoadIdentity() |
217
577f45454402
Change background during spellcards.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
205
diff
changeset
|
95 |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
96 if game is not None and game.spellcard_effect is not None: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
97 if self.use_fixed_pipeline: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
98 glMatrixMode(GL_MODELVIEW) |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
99 glLoadMatrixf(self.game_mvp.data) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
100 glDisable(GL_FOG) |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
101 else: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
102 self.game_shader.bind() |
424
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
103 self.game_shader.uniform_matrix('mvp', self.game_mvp) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
104 |
306
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
304
diff
changeset
|
105 self.render_elements([game.spellcard_effect]) |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
106 elif self.background_renderer is not None: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
107 back = self.background_renderer.background |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
108 x, y, z = back.position_interpolator.values |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
109 dx, dy, dz = back.position2_interpolator.values |
399
1c773544eaeb
Make the background use a single vbo and offsets, just like the 2D code.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
398
diff
changeset
|
110 fog_b, fog_g, fog_r, fog_start, fog_end = back.fog_interpolator.values |
1c773544eaeb
Make the background use a single vbo and offsets, just like the 2D code.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
398
diff
changeset
|
111 |
401
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
112 # Those two lines may come from the difference between Direct3D and |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
113 # OpenGL’s distance handling. The first one seem to calculate fog |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
114 # from the eye, while the second does that starting from the near |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
115 # plane. |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
116 #TODO: investigate, and use a variable to keep the near plane |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
117 # distance at a single place. |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
118 fog_start -= 101010101./2010101. |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
119 fog_end -= 101010101./2010101. |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
120 |
399
1c773544eaeb
Make the background use a single vbo and offsets, just like the 2D code.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
398
diff
changeset
|
121 model = Matrix() |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
122 model.data[12] = -x |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
123 model.data[13] = -y |
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
124 model.data[14] = -z |
412
5fe6cd6ceb48
Refactor the maths functions out of Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
406
diff
changeset
|
125 view = setup_camera(dx, dy, dz) |
424
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
126 mvp = model * view * self.proj |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
127 |
399
1c773544eaeb
Make the background use a single vbo and offsets, just like the 2D code.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
398
diff
changeset
|
128 if self.use_fixed_pipeline: |
401
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
129 glMatrixMode(GL_MODELVIEW) |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
130 glLoadMatrixf(mvp.data) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
131 |
401
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
132 glEnable(GL_FOG) |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
133 glFogi(GL_FOG_MODE, GL_LINEAR) |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
134 glFogf(GL_FOG_START, fog_start) |
3ce4065840e9
Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
135 glFogf(GL_FOG_END, fog_end) |
424
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
136 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
137 fog_data[0] = fog_r / 255. |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
138 fog_data[1] = fog_g / 255. |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
139 fog_data[2] = fog_b / 255. |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
140 fog_data[3] = 1. |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
141 glFogfv(GL_FOG_COLOR, fog_data) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
142 else: |
399
1c773544eaeb
Make the background use a single vbo and offsets, just like the 2D code.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
398
diff
changeset
|
143 self.background_shader.bind() |
424
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
144 self.background_shader.uniform_matrix('mvp', mvp) |
399
1c773544eaeb
Make the background use a single vbo and offsets, just like the 2D code.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
398
diff
changeset
|
145 |
424
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
146 self.background_shader.uniform_1('fog_scale', 1. / (fog_end - fog_start)) |
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
147 self.background_shader.uniform_1('fog_end', fog_end) |
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
148 self.background_shader.uniform_4('fog_color', fog_r / 255., fog_g / 255., fog_b / 255., 1.) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
149 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
150 self.background_renderer.render_background() |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
151 else: |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
152 glClear(GL_COLOR_BUFFER_BIT) |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
153 |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 if game is not None: |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
155 if self.use_fixed_pipeline: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
156 glMatrixMode(GL_MODELVIEW) |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
157 glLoadMatrixf(self.game_mvp.data) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
158 glDisable(GL_FOG) |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
159 else: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
160 self.game_shader.bind() |
424
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
161 self.game_shader.uniform_matrix('mvp', self.game_mvp) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
162 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
163 self.render_elements([enemy for enemy in game.enemies if enemy.visible]) |
166
dcf32488a2c9
Better enemy death, with animation and (hopefully) correct flags handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
164
diff
changeset
|
164 self.render_elements(game.effects) |
201 | 165 self.render_elements(chain(game.players_bullets, |
294
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
286
diff
changeset
|
166 game.lasers_sprites(), |
201 | 167 game.players, |
384
690b5faaa0e6
Make rendering of multiple-sprites elements work like single-sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
383
diff
changeset
|
168 game.msg_sprites())) |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
169 self.render_elements(chain(game.bullets, game.lasers, |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
170 game.cancelled_bullets, game.items, |
384
690b5faaa0e6
Make rendering of multiple-sprites elements work like single-sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
383
diff
changeset
|
171 game.labels)) |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
172 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
464
diff
changeset
|
173 if game.msg_runner is not None: |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
174 rect = Rect(48, 368, 288, 48) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
175 color1 = Color(0, 0, 0, 192) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
176 color2 = Color(0, 0, 0, 128) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
177 self.render_quads([rect], [(color1, color1, color2, color2)], 0) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
178 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
179 glDisable(GL_SCISSOR_TEST) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
180 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
181 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
182 cdef void render_text(self, texts): |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
183 cdef NativeText label |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
184 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
185 if self.font_manager is None: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
186 return |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
187 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
188 labels = [label for label in texts if label is not None] |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
189 self.font_manager.load(labels) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
190 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
191 black = Color(0, 0, 0, 255) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
192 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
193 for label in labels: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
194 if label is None: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
195 continue |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
196 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
197 rect = Rect(label.x, label.y, label.width, label.height) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
198 gradient = [Color(*color, a=label.alpha) for color in label.gradient] |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
199 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
200 if label.shadow: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
201 shadow_rect = Rect(label.x + 1, label.y + 1, label.width, label.height) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
202 shadow = [black._replace(a=label.alpha)] * 4 |
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
503
diff
changeset
|
203 self.render_quads([shadow_rect, rect], [shadow, gradient], (<Texture>label.texture).texture) |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
204 else: |
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
503
diff
changeset
|
205 self.render_quads([rect], [gradient], (<Texture>label.texture).texture) |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
206 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
207 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
208 cdef void render_interface(self, interface, game_boss): |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
209 cdef GlyphCollection label |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
468
diff
changeset
|
210 |
459
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
211 elements = [] |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
212 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
213 if self.use_fixed_pipeline: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
214 glMatrixMode(GL_MODELVIEW) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
215 glLoadMatrixf(self.interface_mvp.data) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
216 glDisable(GL_FOG) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
217 else: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
218 self.interface_shader.bind() |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
219 self.interface_shader.uniform_matrix('mvp', self.interface_mvp) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
220 glViewport(0, 0, interface.width, interface.height) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
221 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
222 items = [item for item in interface.items if item.anmrunner and item.anmrunner.running] |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
223 labels = interface.labels.values() |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
224 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
225 if items: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
226 # Redraw all the interface |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
227 elements.extend(items) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
228 else: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
229 # Redraw only changed labels |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
230 labels = [label for label in labels if label.changed] |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
231 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
232 elements.extend(interface.level_start) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
233 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
234 if game_boss is not None: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
235 elements.extend(interface.boss_items) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
236 |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
237 elements.extend(labels) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
238 self.render_elements(elements) |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
239 for label in labels: |
6e733ed817bd
Move every rendering function from gamerunner to gamerenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
458
diff
changeset
|
240 label.changed = False |