Last modified 27 June 2003 by jdavis@math.wisc.edu
Inherits from SMKResource : NSObject
SMKTexture manages a two-dimensional OpenGL texture. Most of its work is done by overriding SMKResource's resourceWithKey:manager:. This method creates an SMKTexture from a TIFF file in the standard resource location, as described by SMKResource, except that the extension on the file is always ".tiff". The image is loaded into an OpenGL texture object. If an error occurs, then nil is returned.
Here are some technical details. The TIFF file is assumed to be non-planar and in 32-bit RGBA. It is upside-down, in that a texture coordinate of (0, 0) will map to the upper left corner, not the lower left. Its width and height (in pixels) must be powers of 2. SMKTexture does not support texture borders. The texture parameters are left as OpenGL initializes them: They repeat in both directions, linear filtering is used for magnification, nearest-pixel filtering with linear mipmap interpolation is used for minification, and the texture mode is modulation. Future versions of the SMea Kit may change these defaults.
In SMKTexture, both resourceWithKey:manager: and dealloc issue OpenGL commands. The former calls this initialization method:
- (id)initWithTextureName:(unsigned int)textureName width:(unsigned int)width height:(unsigned int)height;Sets the OpenGL texture name, width, and height, and returns the receiver.
Returns the OpenGL texture name.
Returns the texture's width.
Returns the texture's height.
With some knowledge of OpenGL you can pull off fun tricks, such as dynamically replacing part of a texture with a video stream. The textureName, width, and height methods above help you interface with OpenGL. For more elementary use of textures, this method is all you need to know:
- (id)apply;Binds the texture, so that it applies to subsequent OpenGL operations, and returns the receiver. This method issues OpenGL commands.
The apply method lets you exchange one OpenGL texture for another. There are occasions when you want to use no texture at all; the following class method nullifies the current texture without specifying a new one.
+ (void)applyNoTexture;Binds the vacuous 0 texture, so that no texture affects subsequent OpenGL operations. This method issues OpenGL commands.