Up: OpenGL Quick Reference Guide
Previous: Blending and Fog:
Texture mapping is the process of taking an image, presented typically
as a 2-dimensional array of RGB values and mapping it onto a polygon.
Setting up texture mapping involves the following steps: define a
texture by specifying the image and its format (through
glTexImage2d(), specify how object vertices correspond to points in the
texture, and finally enable texture mapping. First, the texture must be
input or generated by the program. OpenGL provides a wide variety of
other features, but we will only summarize a few here, which are
sufficient for handling a single 2-dimensional texture. To handle
multiple textures, see the commands glGenTextures() and
- glTexImage2D(GLenum target, int level,
int internalFormat, int width, int height,
int border, GLenum format, GLenum type, void *pixels):
This converts a texture stored in the array pixels into
an internal format and stored in pixels. The first
argument is typically GL_TEXTURE_2D. The other
arguments specify various elements of how the mapping is to be
performed. See the reference manual for complete information.
- glTexEnvf(GLenum target, GLenum pname, GLfloat param):
Specifies texture mapping environment parameters. The target
must be GL_TEXTURE_ENV. The pname must be
GL_TEXTURE_ENV_MODE. This determines how a color from
the texture image is to be merged with an existing color on the
surface of the polygon. The param may be any of the following:
There are subtle differences between GL_DECAL and
GL_REPLACE when different formats are used or when the
A component of the RGBA color is not 1. See the reference
manual. The default is GL_MODULATE.
- GL_MODULATE: multiply color components together.
- GL_BLEND: linearly blend color components.
- GL_DECAL: use the texture color.
- GL_REPLACE: use the texture color.
- glTexParameterf(GLenum target, GLenum pname, GLfloat param):
- glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params):
Specify how texture interpolation is to be performed.
The first version is for defining scalar parameters, and the
second is for vector parameters.
Assuming 2-dimensional textures, the target is GL_TEXTURE_2D,
the pname is either:
Magnification is used when a pixel of the texture is smaller than
the corresponding pixel of the screen onto which it is mapped and
minification applies in the opposite case. Typical values
- GL_TEXTURE_MAG_FILTER: magnification filter.
- GL_TEXTURE_MIN_FILTER: minification filter.
This procedure may also be invoked to specify other properties
of texture mapping.
- GL_NEAREST: take the nearest texture pixel.
- GL_LINEAR: take the weighted average of
the 4 surrounding texture pixels.
Specifies the texture coordinates of subsequently defined
vertices for texture mapping. For a standard 2-dimensional
textures, the texture coordinates are a pair (s,t) in the
interval . The texture coordinate specifies
the point on the image that are to be mapped to this vertex.
OpenGL interpolates the mapping of intermediate points of the
Please report any errors or send comments to
Last updated: Sat, Feb 8, 2003.