voxel_engine/textures.py

32 lines
820 B
Python
Raw Normal View History

2023-10-19 12:59:58 +02:00
#!/usr/bin/python3
import pygame as pg
import moderngl as mgl
class Textures:
def __init__(self, app):
self.app = app
self.ctx = app.ctx
# load textures
#self.texture_0 = self.load("frame.png")
self.texture_0 = self.load("test.png")
# assign texture unit
self.texture_0.use(location=0)
def load(self, file_name):
texture = pg.image.load(f"assets/{file_name}")
texture = pg.transform.flip(texture, flip_x=True, flip_y=False)
texture = self.ctx.texture(
size=texture.get_size(),
components=4,
data=pg.image.tostring(texture, "RGBA", False)
)
texture.anisotropy = 32.0
texture.build_mipmaps()
texture.filter = (mgl.NEAREST, mgl.NEAREST)
return texture