Mercurial > touhou
comparison pytouhou/ui/background.py @ 205:ee6dfd14a785
Rename pytouhou.opengl to pytouhou.ui, makes much more sense that way.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 01 Nov 2011 13:50:33 +0100 |
parents | pytouhou/opengl/background.py@0313ca2c50e9 |
children |
comparison
equal
deleted
inserted
replaced
204:88361534c77e | 205:ee6dfd14a785 |
---|---|
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 .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', *uvs) | |
42 colors = pack(str(4 * nb_vertices) + 'B', *colors) | |
43 | |
44 background._rendering_data = [(key, (nb_vertices, vertices, uvs, colors))] | |
45 | |
46 return background._rendering_data |