-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture.py
28 lines (23 loc) · 894 Bytes
/
texture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pygame as pg
import moderngl as mgl
class Texture:
def __init__(self, ctx):
self.ctx = ctx
self.textures = {}
def get_texture(self, path):
if path in self.textures.keys():
return self.textures[path]
else:
texture = pg.image.load(path).convert()
texture = pg.transform.flip(texture, flip_x=False, flip_y=True)
texture = self.ctx.texture(size=texture.get_size(), components=3,
data=pg.image.tostring(texture, 'RGB'))
# mipmaps
texture.filter = (mgl.LINEAR_MIPMAP_LINEAR, mgl.LINEAR)
texture.build_mipmaps()
# AF
texture.anisotropy = 32.0
self.textures[path] = texture
return texture
def destroy(self):
[tex.release() for tex in self.textures.values()]