diff options
author | rom <romangraef@gmail.com> | 2021-04-24 13:21:39 +0200 |
---|---|---|
committer | rom <romangraef@gmail.com> | 2021-04-24 13:21:39 +0200 |
commit | a256fbb509af82c7b9c8a03224dfe225e0c123ca (patch) | |
tree | 0ff81359b096469f79700d762d840e58f29bbf48 /txtgameengine/twod/textures.py | |
parent | ec934bf2f0f3536c1b4d31b4ca002f6f38ada9fe (diff) | |
download | txtgameengine-master.tar.gz txtgameengine-master.tar.bz2 txtgameengine-master.zip |
Diffstat (limited to 'txtgameengine/twod/textures.py')
-rw-r--r-- | txtgameengine/twod/textures.py | 17 |
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) |