[go: up one dir, main page]

Menu

[r339]: / tda / new / util.py  Maximize  Restore  History

Download this file

36 lines (25 with data), 941 Bytes

 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
29
30
31
32
33
34
35
import pygame
from OpenGL.GL import *
class Texture:
def __init__(self, texture, width, height):
self.texture = texture
self.width = width
self.height = height
def get_width(self):
return self.width
def get_height(self):
return self.height
def load_gl_texture(file):
return make_gl_texture(pygame.image.load(file).convert_alpha())
def make_gl_texture(img):
data = pygame.image.tostring(img, "RGBA", 1)
width = img.get_width()
height = img.get_height()
texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texture)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data)
return Texture(texture, width, height)
def delete_gl_texture(texture):
glDeleteTextures(texture)