OpenGLContext.texture
Resource-manager for textures (with PIL conversions)
Functions
getLengthFormat(
image
)
Return PIL image component-length and format
This returns the number of components, and the OpenGL
mode constant describing the PIL image's format. It
currently only supports GL_RGBA, GL_RGB and GL_LUMINANCE
formats (PIL: RGBA, RGBX, RGB, and L), the Texture
object's ensureRGB converts Paletted images to RGB
before they reach this function.
Classes
class CubeTexture(
Texture
):
Mip-mapped texture object
Note: You'll want your images to use
minFilter = GL_LINEAR_MIPMAP_NEAREST
to actually see any effect from using a
MMTexture.
class NumpyAdapter(
object
):
Holder for an OpenGL compiled texture
This object holds onto a texture until it
is deleted. Provides methods for storing
raw data or PIL images (store and fromPIL
respectively)
Attributes:
components -- number of components in the image,
if 0, then there is no currently stored image
texture -- OpenGL textureID as returned by a call
to glGenTextures(1), will be freed when the
Texture object is deleted
format -- GL_RGB/GL_RGBA/GL_LUMINANCE
__init__(
self
,
image
= None
,
format
= None
)
Initialise the texture, if image is not None, store it
- image
- optional PIL image to store
ensurePow2(
self
,
image
)
Ensure that the PIL image is pow2 x pow2 dimensions
Note:
This method will create a _new_ PIL image if
the image is not a valid size (It will use BICUBIC
filtering (from PIL) to do the resizing). Otherwise
just returns the same image object.
ensureRGB(
self
,
image
)
Ensure that the PIL image is in RGB mode
Note:
This method will create a _new_ PIL image if
the image is in Paletted mode, otherwise just
returns the same image object.
fromPIL(
self
,
image
)
Automated storage of image data from a PIL Image instance
Uses the ensureRGB method to convert the image to RGB,
then ensurePow2 to make the image a valid size for OpenGL,
then calls self.store(...) with the appropriate arguments.
Returns the number of components in the image
store(
self
,
components
,
format
,
x
,
y
,
image
)
define the texture's parameters...
components -- number of components (3 or 4 for
RGB and RGBA respectively)
format -- GL_RGB, GL_RGBA, GL_LUMINANCE
x,y -- dimensions of the image
image -- string, data in raw (unencoded) format
See:
glBindTexture, glPixelStorei, glTexImage2D