2010 October 12 / j|d|a|v|i|s|@|c|a|r|l|e|t|o|n|.|e|d|u

Texture

A 2D texture to be applied to 2D and 3D bodies. Usually one builds a texture using the constructor functions below, rather than using the class' constructor method directly.

__init__(self, data, width, height, isRepeating)

The data argument is a string of bytes, of length = width x height x numChannels, in row-major order. The width and height need not be powers of 2, but the image will be padded out as if they were powers of 2. The isRepeating Boolean indicates how texture coordinates beyond [0, 1] (and at the boundary) are handled; either by repeating the texture or clamping to the edge value.

getBigWidthHeight(self)

Returns the internal width and height in pixels. These are integers, always powers of 2 --- namely, the first powers of 2 greater than or equal to the width and height.

getWidthHeight(self)

Returns the width and height in pixels. These are integers, not necessarily powers of 2.

getNumChannels(self)

Returns the number of channels per pixel.

getFormat(self)

Returns GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, or GL_RGBA (which are defined in the module OpenGL.GL).

Constructor Functions

makeFileTexture(path, isRepeating=False)

Returns a Texture object initialized from a graphics file at the given path. The isRepeating Boolean indicates how texture coordinates beyond [0, 1] (and at the boundary) are handled --- either by repeating the texture or clamping to the edge value. If the file cannot be found, then None is returned.

makeTextTexture(string, fontPath, fontSize)

Returns a Texture object containing an image of a string of text, drawn in a given TrueType font and size. On Mac OS X a typical fontPath is '/Library/Fonts/Silom.ttf'. A typical size is 12 or 18. In the text image, the text is opaque white, the background is transparent white, and antialiasing is accomplished by opacity.

makeWhiteTexture()

Returns a 1x1 opaque white texture.