Mercurial > touhou
comparison pytouhou/opengl/background.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 | 0313ca2c50e9 |
comparison
equal
deleted
inserted
replaced
107:5d9052b9a4e8 | 108:2a03940deea3 |
---|---|
1 # -*- encoding: utf-8 -*- | |
2 ## | |
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> | |
4 ## | |
5 ## This program is free software; you can redistribute it and/or modify | |
6 ## it under the terms of the GNU General Public License as published | |
7 ## by the Free Software Foundation; version 3 only. | |
8 ## | |
9 ## This program is distributed in the hope that it will be useful, | |
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ## GNU General Public License for more details. | |
13 ## | |
14 | |
15 #TODO: lots of things | |
16 | |
17 from struct import pack | |
18 from itertools import chain | |
19 | |
20 from pytouhou.opengl.sprite import get_sprite_rendering_data | |
21 | |
22 def get_background_rendering_data(background): | |
23 #TODO | |
24 try: | |
25 return background._rendering_data | |
26 except AttributeError: | |
27 pass | |
28 | |
29 vertices = [] | |
30 uvs = [] | |
31 colors = [] | |
32 for ox, oy, oz, model_id, model in background.object_instances: | |
33 for ox2, oy2, oz2, width_override, height_override, sprite in model: | |
34 key, (vertices2, uvs2, colors2) = get_sprite_rendering_data(sprite) | |
35 vertices.extend((x + ox + ox2, y + oy + oy2, z + oz + oz2) for x, y, z in vertices2) | |
36 uvs.extend(uvs2) | |
37 colors.extend(colors2) | |
38 | |
39 nb_vertices = len(vertices) | |
40 vertices = pack(str(3 * nb_vertices) + 'f', *chain(*vertices)) | |
41 uvs = pack(str(2 * nb_vertices) + 'f', *chain(*uvs)) | |
42 colors = pack(str(4 * nb_vertices) + 'B', *chain(*colors)) | |
43 | |
44 background._rendering_data = [(key, (nb_vertices, vertices, uvs, colors))] | |
45 | |
46 return background._rendering_data |