summaryrefslogtreecommitdiff
path: root/txtgameengine/twod/textures.py
diff options
context:
space:
mode:
Diffstat (limited to 'txtgameengine/twod/textures.py')
-rw-r--r--txtgameengine/twod/textures.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/txtgameengine/twod/textures.py b/txtgameengine/twod/textures.py
index 295af27..a17472e 100644
--- a/txtgameengine/twod/textures.py
+++ b/txtgameengine/twod/textures.py
@@ -11,17 +11,28 @@ if typing.TYPE_CHECKING:
class Texture:
- def __init__(self, app: 'TxtGameApp', path: os.PathLike):
+ def __init__(self, app: 'TxtGameApp', load: typing.Union[os.PathLike, Image.Image]):
self.app = app
- self.path = path
+ self.load = load
self._bind_to_gl()
def _bind_to_gl(self):
- image = Image.open(self.path)
+ if isinstance(self.load, Image.Image):
+ image = self.load
+ else:
+ image = Image.open(str(self.load))
self.width, self.height = image.size
+ image = image.convert('RGBA')
imagedata = np.array(list(image.getdata()), np.uint8)
self.gl_texid = self.app.render.setup_texture(self.width, self.height, imagedata)
image.close()
+ @property
+ def size(self):
+ return self.width, self.height
+
+ def uvs_from_pixels(self, x: int, y: int) -> typing.Tuple[float, float]:
+ return self.app.coords.from_pixels_to_uvs(self.size, x, y)
+
def free(self):
self.app.render.free_texture(self.gl_texid)