summaryrefslogtreecommitdiff
path: root/txtgameengine/twod
diff options
context:
space:
mode:
authorJonas Bernard <public.jbernard@web.de>2021-04-24 01:45:27 +0200
committerJonas Bernard <public.jbernard@web.de>2021-04-24 01:45:27 +0200
commitd4f6d3919e992ed9bb8d43833c694e431c9735c9 (patch)
tree39691ee36a7039dc3f0381013ef7b7bce9069b65 /txtgameengine/twod
parentfd73d0ad2c3b54850baf3c467954c92bd40ed010 (diff)
downloadtxtgameengine-d4f6d3919e992ed9bb8d43833c694e431c9735c9.tar.gz
txtgameengine-d4f6d3919e992ed9bb8d43833c694e431c9735c9.tar.bz2
txtgameengine-d4f6d3919e992ed9bb8d43833c694e431c9735c9.zip
Texture
Diffstat (limited to 'txtgameengine/twod')
-rw-r--r--txtgameengine/twod/textures.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/txtgameengine/twod/textures.py b/txtgameengine/twod/textures.py
index 01dde52..0451e5c 100644
--- a/txtgameengine/twod/textures.py
+++ b/txtgameengine/twod/textures.py
@@ -1,11 +1,27 @@
import typing
+from PIL import Image
+import numpy as np
+
+TEXTURE_FOLDER = 'txtgameengine/res/textures/'
if typing.TYPE_CHECKING:
from ..app import TxtGameApp
class Texture:
- def __init__(self, app: 'TxtGameApp', gl_texid: int):
+ def __init__(self, app: 'TxtGameApp', path: str):
self.app = app
- self.gl_texid = gl_texid
+ self.path = path
+ self._load_from_disk()
+ self._bind_to_gl()
+
+ def _load_from_disk(self):
+ self.image = Image.open(TEXTURE_FOLDER + self.path)
+ self.width, self.height = self.image.size
+
+ def _bind_to_gl(self):
+ imagedata = np.array(list(self.image.getdata()), np.uint8)
+ self.gl_texid = self.app.render.setup_texture(self.width, self.height, imagedata)
+ def free(self):
+ self.app.render.free_texture(self.gl_texid) \ No newline at end of file