-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
26 lines (19 loc) · 845 Bytes
/
utils.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
from OpenGL.GL import *
from PIL import Image
import numpy as np
def sizeof(x: np.array) -> int:
return x.size * x.itemsize
def create_texture(texturePath: str):
texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texture)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
tex = Image.open(texturePath, mode='r')
img_data = np.array(list(tex.getdata()), np.uint8)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, tex.width, tex.height, 0,
GL_RGB, GL_UNSIGNED_BYTE, img_data)
glGenerateMipmap(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, 0) # Unbind texture
return texture