summaryrefslogtreecommitdiff
path: root/txtgameengine/twod/textures.py
diff options
context:
space:
mode:
authorrom <romangraef@gmail.com>2021-04-24 13:21:39 +0200
committerrom <romangraef@gmail.com>2021-04-24 13:21:39 +0200
commita256fbb509af82c7b9c8a03224dfe225e0c123ca (patch)
tree0ff81359b096469f79700d762d840e58f29bbf48 /txtgameengine/twod/textures.py
parentec934bf2f0f3536c1b4d31b4ca002f6f38ada9fe (diff)
downloadtxtgameengine-a256fbb509af82c7b9c8a03224dfe225e0c123ca.tar.gz
txtgameengine-a256fbb509af82c7b9c8a03224dfe225e0c123ca.tar.bz2
txtgameengine-a256fbb509af82c7b9c8a03224dfe225e0c123ca.zip
text rendering lulHEADmaster
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)