annotate pytouhou/opengl/gamerenderer.py @ 108:2a03940deea3

Move everything graphical to pytouhou.opengl!
author Thibaut Girka <thib@sitedethib.com>
date Tue, 06 Sep 2011 00:26:13 +0200
parents
children 340fcda8e64a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15 import struct
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
16 from itertools import chain
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18 import pygame
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
20 import OpenGL
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
21 OpenGL.FORWARD_COMPATIBLE_ONLY = True
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22 from OpenGL.GL import *
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23 from OpenGL.GLU import *
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
24
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
26 from pytouhou.opengl.texture import TextureManager
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
27 from pytouhou.opengl.sprite import get_sprite_rendering_data
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
28 from pytouhou.opengl.background import get_background_rendering_data
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
30
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
31 class GameRenderer(object):
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
32 def __init__(self, resource_loader, game=None, background=None):
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
33 self.texture_manager = TextureManager(resource_loader)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
34
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
35 self.game = game
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36 self.background = background
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
38 self.window = None
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
39
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41 def start(self, width=384, height=448):
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42 # Initialize pygame
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 pygame.init()
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
44 self.window = pygame.display.set_mode((width, height),
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45 pygame.OPENGL | pygame.DOUBLEBUF)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47 # Initialize OpenGL
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
48 glMatrixMode(GL_PROJECTION)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
49 glLoadIdentity()
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50 gluPerspective(30, float(width)/float(height),
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
51 101010101./2010101., 101010101./10101.)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
53 glEnable(GL_BLEND)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54 glEnable(GL_TEXTURE_2D)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
55 glEnable(GL_FOG)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
56 glHint(GL_FOG_HINT, GL_NICEST)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
57 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58 glEnableClientState(GL_COLOR_ARRAY)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
59 glEnableClientState(GL_VERTEX_ARRAY)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
60 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
61
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
62
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
63 def render_elements(self, elements):
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64 texture_manager = self.texture_manager
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
65 objects_by_texture = {}
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
66 for element in elements:
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
67 sprite = element._sprite
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
68 if sprite:
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
69 ox, oy = element.x, element.y
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
70 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
71 rec = objects_by_texture.setdefault(key, ([], [], []))
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
72 vertices = ((x + ox, y + oy, z) for x, y, z in vertices)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
73 rec[0].extend(vertices)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
74 rec[1].extend(uvs)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
75 rec[2].extend(colors)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
76
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77 for (texture_key, blendfunc), (vertices, uvs, colors) in objects_by_texture.items():
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78 nb_vertices = len(vertices)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
79 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
80 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key])
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
81 glVertexPointer(3, GL_FLOAT, 0, struct.pack(str(3 * nb_vertices) + 'f', *chain(*vertices)))
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
82 glTexCoordPointer(2, GL_FLOAT, 0, struct.pack(str(2 * nb_vertices) + 'f', *chain(*uvs)))
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
83 glColorPointer(4, GL_UNSIGNED_BYTE, 0, struct.pack(str(4 * nb_vertices) + 'B', *chain(*colors)))
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
84 glDrawArrays(GL_QUADS, 0, nb_vertices)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
86
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87 def render(self):
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
88 glClear(GL_DEPTH_BUFFER_BIT)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
89
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
90 back = self.background
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
91 game = self.game
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
92 texture_manager = self.texture_manager
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
93
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
94 if back is not None:
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
95 fog_b, fog_g, fog_r, _, fog_start, fog_end = back.fog_interpolator.values
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
96 x, y, z = back.position_interpolator.values
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
97 dx, dy, dz = back.position2_interpolator.values
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
98
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
99 glFogi(GL_FOG_MODE, GL_LINEAR)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
100 glFogf(GL_FOG_START, fog_start)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
101 glFogf(GL_FOG_END, fog_end)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
102 glFogfv(GL_FOG_COLOR, (fog_r / 255., fog_g / 255., fog_b / 255., 1.))
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
103
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
104 glMatrixMode(GL_MODELVIEW)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
105 glLoadIdentity()
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
106 # Some explanations on the magic constants:
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
107 # 192. = 384. / 2. = width / 2.
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
108 # 224. = 448. / 2. = height / 2.
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
109 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2))
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
110 # This is so that objects on the (O, x, y) plane use pixel coordinates
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
111 gluLookAt(192., 224., - 835.979370 * dz,
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
112 192. + dx, 224. - dy, 0., 0., -1., 0.)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
113 glTranslatef(-x, -y, -z)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
114
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
115 glEnable(GL_DEPTH_TEST)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
116 for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back):
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
117 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
118 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key])
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
119 glVertexPointer(3, GL_FLOAT, 0, vertices)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
120 glTexCoordPointer(2, GL_FLOAT, 0, uvs)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
121 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
122 glDrawArrays(GL_QUADS, 0, nb_vertices)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
123 glDisable(GL_DEPTH_TEST)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
124 else:
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
125 glClear(GL_COLOR_BUFFER_BIT)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
126
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
127
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
128 if game is not None:
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
129 glMatrixMode(GL_MODELVIEW)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
130 glLoadIdentity()
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
131 # Some explanations on the magic constants:
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
132 # 192. = 384. / 2. = width / 2.
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
133 # 224. = 448. / 2. = height / 2.
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
134 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2))
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
135 # This is so that objects on the (O, x, y) plane use pixel coordinates
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
136 gluLookAt(192., 224., - 835.979370,
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
137 192., 224., 0., 0., -1., 0.)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
138
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
139 glDisable(GL_FOG)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
140 self.render_elements(game.enemies)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
141 self.render_elements(game.game_state.bullets)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
142 glEnable(GL_FOG)
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
143