next up previous contents
Next: 6.1.2.1 Assigning Texture Coordinates Up: 6.1 Texturing Basics Previous: 6.1.1.1 Internal Texture Formats   Contents

6.1.2 Texture Coordinates

Texture coordinates are the means by which texture image positions are assigned to vertices. The per-vertex assignment of texture coordinates is the key to mapping a texture image to rendered geometry. During rasterization, the texture coordinates of a primitive's vertices are interpolated across the primitive so that each rasterized fragment making up the primitive has an appropriately interpolated texture coordinate. A fragment's texture coordinates are translated into the addresses of one or more texels within the current texture. The texels are fetched and their color values are then filtered into a single texture color value for the fragment. The fragment's texture color is then combined with the fragments color.


% latex2html id marker 4957
\fbox{\begin{tabular}{c}
\vrule width 0pt height 0.1...
...ture are mapped to the
surface of a triangle in object space.}\\
\end{tabular}}

The vertices of all primitives (including the raster position of pixel images) have associated texture coordinates. Figure 27 shows how object coordinates have associated texture coordinates that is used to map into a texture image when texture mapping is enabled. The texture coordinates are part of a three-dimensional homogeneous coordinate system ($s$,$t$,$r$,$q$). Applications often only assign the 2D $s$ and $t$ coordinates, but OpenGL treats this as a special case of the more general 3D homogeneous texture coordinate space. The $r$ and $q$ texture coordinates are vital to techniques that utilize volumetric and projective texturing. When $t$, $r$, or $q$ are not explicitly assigned a value (as when glTexCoord1f() is called), their assumed values are 0, 0, and 1 respectively. If the concept of 3D homogeneous texture coordinates is unfamiliar to your, the topic will be revisited in Section 6.16.

OpenGL's interpolation of texture coordinates across a primitive compensates for the appearance of a textured surface when viewed in perspective. While so-called perspective correct texture coordinate interpolation is more expensive, failing to account for perspective results in incorrect and unsightly distortion of the texture image across the textured primitive's surface.

Each texture coordinate is assumed to be floating-point value. Each set of texture coordinates must be mapped to a position within the texture image. The coordinates of the texture map range from [0..1] in each dimension. OpenGL can treat coordinate values outside the range [0,1] in one of two ways: clamp or repeat. In the case of clamp, the coordinates are simply clamped to [0,1] causing the edge values of the texture to be stretched across the remaining parts of the polygon. In the case of repeat the integer part of the coordinate is discarded so the texture image becomes an infinitely repeated tile pattern. In the case of clamping, proper filtering may require accounting for border texels or, when no border is specified, the texture border color. OpenGL 1.2 adds a variation on clamping known as clamp to edge that clamps such that the border is never sampled.2The filtered color value that results from texturing can be used to modify the original surface color value in one of several ways as determined by the texture environment. The simplest way replaces the surface color with texel color, either by modulating a white polygon or simply replacing the color value. Simple replacement was added as an extension by some vendors to OpenGL 1.0 and is now part of OpenGL 1.1.



Subsections
next up previous contents
Next: 6.1.2.1 Assigning Texture Coordinates Up: 6.1 Texturing Basics Previous: 6.1.1.1 Internal Texture Formats   Contents
2001-01-10