Mercurial > touhou
comparison pytouhou/opengl/texture.py @ 14:07a7f28c8aaa
Minor refactoring
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Fri, 05 Aug 2011 14:54:32 +0200 |
parents | |
children | 07fba4e1da65 |
comparison
equal
deleted
inserted
replaced
13:58bc264aba38 | 14:07a7f28c8aaa |
---|---|
1 import pygame | |
2 import os | |
3 from io import BytesIO | |
4 | |
5 import OpenGL | |
6 OpenGL.FORWARD_COMPATIBLE_ONLY = True | |
7 from OpenGL.GL import * | |
8 from OpenGL.GLU import * | |
9 | |
10 | |
11 def load_texture(archive, anim): | |
12 image_file = BytesIO(archive.extract(os.path.basename(anim.first_name))) | |
13 textureSurface = pygame.image.load(image_file).convert_alpha() | |
14 | |
15 if anim.secondary_name: | |
16 alpha_image_file = BytesIO(archive.extract(os.path.basename(anim.secondary_name))) | |
17 alphaSurface = pygame.image.load(alpha_image_file) | |
18 assert textureSurface.get_size() == alphaSurface.get_size() | |
19 for x in range(alphaSurface.get_width()): | |
20 for y in range(alphaSurface.get_height()): | |
21 r, g, b, a = textureSurface.get_at((x, y)) | |
22 color2 = alphaSurface.get_at((x, y)) | |
23 textureSurface.set_at((x, y), (r, g, b, color2[0])) | |
24 | |
25 textureData = pygame.image.tostring(textureSurface, 'RGBA', 1) | |
26 | |
27 width = textureSurface.get_width() | |
28 height = textureSurface.get_height() | |
29 | |
30 texture = glGenTextures(1) | |
31 glBindTexture(GL_TEXTURE_2D, texture) | |
32 | |
33 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, | |
34 GL_UNSIGNED_BYTE, textureData) | |
35 | |
36 return texture, width, height | |
37 |