Graphics Reference
In-Depth Information
Texture wrap modes are used to specify the behavior that occurs when
a texture coordinate is outside of the range [0.0, 1.0]. The texture wrap
modes are set using
glTexParameter[i|f][v]
. Such modes can be
set independently for the
s
-coordinate,
t
-coordinate, and
r
-coordinate.
The
GL_TEXTURE_WRAP_S
mode defines what the behavior is when the
s
-coordinate is outside of the range [0.0, 1.0],
GL_TEXTURE_WRAP_T
sets the
behavior for the
t
-coordinate, and
GL_TEXTURE_WRAP_R
sets the behavior
for the
r
-coordinate (the
r
-coordinate wrapping is used only for 3D
textures and 2D texture arrays). In OpenGL ES, there are three wrap modes
to choose from, as described in Table 9-3.
Table 9-3
Texture Wrap Modes
Texture Wrap Mode
Description
GL_REPEAT
Repeat the texture
GL_CLAMP_TO_EDGE
Clamp fetches to the edge of the texture
GL_MIRRORED_REPEAT
Repeat the texture and mirror
Note that the texture wrap modes also affect the behavior of filtering. For
example, when a texture coordinate is at the edge of a texture, the bilinear
filter kernel might span beyond the edge of the texture. In this case, the
wrap mode will determine which texels are fetched for the portion of the
kernel that lies outside the texture edge. You should use
GL_CLAMP_TO_EDGE
whenever you do not want any form of repeating.
In
Chapter_9/TextureWrap
, there is an example that draws a quad
with each of the three different texture wrap modes. The quads have
a checkerboard image applied to them and are rendered with texture
coordinates in the range from [-1.0, 2.0]. The results are shown in
FigureĀ 9-5.
Figure 9-5
GL_REPEAT, GL_CLAMP_TO_EDGE
, and
GL_MIRRORED_REPEAT
Modes