annotate pytouhou/ui/texture.pyx @ 409:608468be7a93

Move ascii_wrapper to the interface, as it is game-dependent.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 12 Jun 2013 16:03:26 +0200
parents 9e2cbb2c2c64
children 3a7b36324611
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 25
diff changeset
14
368
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
15 from libc.stdlib cimport malloc, free
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
16
119
fad7b44cebf2 Switch from pygame + PyOpenGL to pyglet
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
17 import pyglet
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
18 from pyglet.gl import (glTexParameteri, GL_TEXTURE_MIN_FILTER,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
19 GL_TEXTURE_MAG_FILTER, GL_LINEAR, GL_BGRA, GL_RGBA,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
20 GL_RGB, GL_LUMINANCE, GL_UNSIGNED_BYTE,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
21 GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4_REV,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
22 glGenTextures, glBindTexture, glTexImage2D,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
23 GL_TEXTURE_2D)
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
24 from ctypes import c_uint, byref
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25 import os
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
26
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
27 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere?
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
28
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29
223
98c64ffcbdff Make pytouhou.ui.{background,texture} Cython modules as they are only used by Cython modules.
Thibaut Girka <thib@sitedethib.com>
parents: 205
diff changeset
30 cdef class TextureManager:
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
31 def __init__(self, loader=None):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents: 83
diff changeset
32 self.loader = loader
16
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
33 self.textures = {}
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
34
158
7769ce7be03c Minor cleanup
Thibaut Girka <thib@sitedethib.com>
parents: 119
diff changeset
35
16
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
36 def __getitem__(self, key):
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
37 if not key in self.textures:
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
38 self.textures[key] = self.load_texture(key)
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
39 return self.textures[key]
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40
16
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
41
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
42 def preload(self, anm_wrapper):
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
43 for anm in anm_wrapper:
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
44 anm.texture = self.load_png_texture(anm.first_name, anm.secondary_name)
25
cc864aadc733 Preload enemy and background textures
Thibaut Girka <thib@sitedethib.com>
parents: 16
diff changeset
45
cc864aadc733 Preload enemy and background textures
Thibaut Girka <thib@sitedethib.com>
parents: 16
diff changeset
46
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
47 def load_png_texture(self, first_name, secondary_name):
392
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
48 cdef char *image, *alpha, *new_data
368
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
49 cdef unsigned int i, width, height, pixels
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
50
119
fad7b44cebf2 Switch from pygame + PyOpenGL to pyglet
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
51 image_file = pyglet.image.load(first_name, file=self.loader.get_file(os.path.basename(first_name)))
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
52 width, height = image_file.width, image_file.height
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
53 image_data = image_file.get_data('RGB', width * 3)
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54
16
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
55 if secondary_name:
119
fad7b44cebf2 Switch from pygame + PyOpenGL to pyglet
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
56 alpha_file = pyglet.image.load(secondary_name, file=self.loader.get_file(os.path.basename(secondary_name)))
fad7b44cebf2 Switch from pygame + PyOpenGL to pyglet
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
57 assert (image_file.width, image_file.height) == (alpha_file.width, image_file.height)
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58
368
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
59 pixels = width * height
392
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
60
368
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
61 alpha_data = alpha_file.get_data('RGB', width * 3)
392
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
62 image = <char *>image_data
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
63 alpha = <char *>alpha_data
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64
368
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
65 # TODO: further optimizations
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
66 new_data = <char *>malloc(pixels * 4)
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
67 for i in range(pixels):
392
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
68 new_data[i*4] = image[i*3]
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
69 new_data[i*4+1] = image[i*3+1]
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
70 new_data[i*4+2] = image[i*3+2]
45e1a9a37e66 When merging RGB and alpha data, get the C arrays only at the start of the loop.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 368
diff changeset
71 new_data[i*4+3] = alpha[i*3]
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
72 data = new_data[:(pixels * 4)]
368
71cd4461bb7f Minor optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 223
diff changeset
73 free(new_data)
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
74 return Texture(width, height, -4, data)
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
75
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
76 return Texture(width, height, -3, image_data)
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
77
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
78
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
79 def load_texture(self, key):
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
80 if not isinstance(key, Texture):
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
81 first_name, secondary_name = key
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
82 key = self.load_png_texture(first_name, secondary_name)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents: 14
diff changeset
83
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
84 if key.fmt == 1:
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
85 format_ = GL_BGRA
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
86 type_ = GL_UNSIGNED_BYTE
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
87 composants = GL_RGBA
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
88 elif key.fmt == 3:
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
89 format_ = GL_RGB
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
90 type_ = GL_UNSIGNED_SHORT_5_6_5
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
91 composants = GL_RGB
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
92 elif key.fmt == 5:
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
93 format_ = GL_BGRA
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
94 type_ = GL_UNSIGNED_SHORT_4_4_4_4_REV
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
95 composants = GL_RGBA
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
96 elif key.fmt == 7:
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
97 format_ = GL_LUMINANCE
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
98 type_ = GL_UNSIGNED_BYTE
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
99 composants = GL_LUMINANCE
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
100 elif key.fmt == -3: #XXX: non-standard, remove it!
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
101 format_ = GL_RGB
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
102 type_ = GL_UNSIGNED_BYTE
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
103 composants = GL_RGB
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
104 elif key.fmt == -4: #XXX: non-standard
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
105 format_ = GL_RGBA
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
106 type_ = GL_UNSIGNED_BYTE
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
107 composants = GL_RGBA
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
108 else:
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
109 raise Exception('Unknown texture type')
14
07a7f28c8aaa Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
110
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
111 id_ = c_uint()
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
112 glGenTextures(1, byref(id_))
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
113 glBindTexture(GL_TEXTURE_2D, id_.value)
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
16
66ce9bb440ac Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
116
393
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
117 glTexImage2D(GL_TEXTURE_2D, 0,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
118 composants,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
119 key.width, key.height,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
120 0,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
121 format_, type_,
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
122 key.data)
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
123
9e2cbb2c2c64 Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 392
diff changeset
124 return id_.value