"""
A OpenGL texture class
"""

from OpenGL.GL import *
import pygame

class Texture(object):
  """An OpenGL texture"""

  def __init__(self, file_):
    # Load and allocate the texture
    self.surface = pygame.image.load(file_).convert_alpha()
    self.__texture = glGenTextures(1)
    self.reload()

  def reload(self):
    # Set up the texture
    glEnable(GL_TEXTURE_2D)
    glBindTexture(GL_TEXTURE_2D, self.__texture)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.w, self.h, 0, GL_RGBA,
      GL_UNSIGNED_BYTE, pygame.image.tostring(self.surface, "RGBA", True))

  def bind(self):
    glBindTexture(GL_TEXTURE_2D, self.__texture)

  w = property(lambda self: self.surface.get_width())
  h = property(lambda self: self.surface.get_height())

@@ -151,27 +151,28 @@
     
-# Load and allocate
+%22%22%22Allocate and load
  the
@@ -175,24 +175,27 @@
  the texture
+%22%22%22
 %0A    self.su
@@ -306,22 +306,23 @@
 %0A%0A  def 
-reload
+__del__
 (self):%0A
@@ -329,16 +329,18 @@
     
-# Set up
+%22%22%22Release
  the
@@ -351,36 +351,98 @@
 ture
+%22%22%22
 %0A    gl
-Enable(GL_TEXTURE_2D)
+DeleteTextures(%5Bself.__texture%5D)%0A%0A  def reload(self):%0A    %22%22%22Load the texture%22%22%22
 %0A   
@@ -917,24 +917,88 @@
 bind(self):%0A
+    %22%22%22Make the texture active in the current OpenGL context%22%22%22%0A
     glBindTe

Remove resource leak in Texture