14
|
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
|
15
|
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
|
37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
|
38
|
14
|
39 return texture, width, height
|
|
40
|