You can assign texture coordinates outside the range [0,1] and have them either clamp or repeat in the texture map. With repeating textures, if you have a large plane with texture coordinates running from 0.0 to 10.0 in both directions, for example, you'll get 100 copies of the texture tiled together on the screen. During repeating, the integer part of texture coordinates is ignored, and copies of the texture map tile the surface. For most applications where the texture is to be repeated, the texels at the top of the texture should match those at the bottom, and similarly for the left and right edges.
The other possibility is to clamp the texture coordinates: Any values greater than 1.0 are set to 1.0, and any values less than 0.0 are set to 0.0. Clamping is useful for applications where you want a single copy of the texture to appear on a large surface. If the surface-texture coordinates range from 0.0 to 10.0 in both directions, one copy of the texture appears in the lower corner of the surface. The rest of the surface is painted with the texture's border colors as needed. If you've chosen GL_LINEAR as the filtering method (see "Controlling Filtering" ), an equally weighted combination of the border color and the texture color is used, as follows:
When repeating, the 2 × 2 array wraps to the opposite edge of the texture. Thus, texels on the right edge are averaged with those on the left, and top and bottom texels are also averaged.
If there is a border, then the texel from the border is used. Otherwise, GL_TEXTURE_BORDER_COLOR is used.
Note that you can avoid having the rest of the surface affected by the texture. To do this, use blending with alpha values of 0 to eliminate the drawing. (See "Blending." )
If you haven't specified a border with glTexImage*d(), the color value of GL_TEXTURE_BORDER_COLOR is used to paint the rest of the surface. By default, this value is (0, 0, 0, 0); use glTexParameter*() to change this value, as described near the end of this section.
In Example 9-1 , if the texture coordinates for the squares are mapped from 0.0 to 3.0 as follows, the result is as shown in Figure 9-6 .
glBegin(GL_POLYGON); glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); glTexCoord2f(0.0, 3.0); glVertex3f(-2.0, 1.0, 0.0); glTexCoord2f(3.0, 3.0); glVertex3f(0.0, 1.0, 0.0); glTexCoord2f(3.0, 0.0); glVertex3f(0.0, -1.0, 0.0); glEnd(); glBegin(GL_POLYGON); glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glTexCoord2f(0.0, 3.0); glVertex3f(1.0, 1.0, 0.0); glTexCoord2f(3.0, 3.0); glVertex3f(2.41421, 1.0, -1.41421); glTexCoord2f(3.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421); glEnd();
![[IMAGE]](figures/repeat.gif)
Figure 9-6 : Repeating a Texture
In this case, the texture is repeated in both the s and t directions, since the following calls are made to glTexParameter*():
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_S_WRAP, GL_REPEAT); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_T_WRAP, GL_REPEAT);
If GL_CLAMP is used instead of GL_REPEAT, you see the picture shown in Figure 9-7 .
![[IMAGE]](figures/clamp.gif)
Figure 9-7 : Clamping a Texture
Notice that the border colors are continued outside the range of the texture map. You can also clamp in one direction and repeat in the other, as shown in Figure 9-8 .
![[IMAGE]](figures/wrap.gif)
Figure 9-8 : Repeating and Clamping a Texture
You've now seen all the possible arguments for glTexParameter*(), which is summarized here. void glTexParameter{if}{v}(GLenum target, GLenum pname, TYPE param);
Sets various parameters that control how a texture is treated as it's applied to a fragment. The target parameter is either GL_TEXTURE_2D or GL_TEXTURE_1D to indicate a two- or one-dimensional texture. The possible values for pname and param are shown in Table 9-3 . You can use the vector version of the command to supply an array of values for GL_TEXTURE_BORDER_COLOR, or you can supply them individually using the nonvector version. If these values are supplied as integers, they're converted to floating-point according to Table 5-1 ; they're also clamped to the range [0,1]
| Parameter | Values |
|---|---|
GL_TEXTURE_WRAP_S | GL_CLAMP, GL_REPEAT |
GL_TEXTURE_WRAP_T | GL_CLAMP, GL_REPEAT |
GL_TEXTURE_MAG_FILTER | GL_NEAREST, GL_LINEAR |
GL_TEXTURE_MIN_FILTER | GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR |
GL_TEXTURE_BORDER_COLOR | any four values in [0, 1] |
OpenGL Programming Guide