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)