Working with Texture Transformations

We studied in the tutorial Texture Coordinates how to apply a image map to a two-dimensional object, namely, a rectangle. Once applied, we can perform the standard transformations of Translate, Scale and Rotate on the texture object. The tutorial 2D Transformations helps you in learning about the transformations and their application to geometric objects. The function calls when applied to a texture mapping are exactly the same. The only difference is setting the current matrix stack so as the transformations are applied to the texture versus the geometry. In particular, we set the matrix mode to GL_TEXTURE with the call

glMatrixMode(GL_TEXTURE).

You see this as one of the lines of code in the Technical Content window once you start interacting and select a transformation to be applied to the texture. As you do so, keep in mind that the transformations are applied to the normal range of texture coordinates. For example, if we select a translation of -0.5 in both the S and T coordinates, then the texture coordinates associated with the vertices of the rectangle are (-0.5, 0.5) for the lower-left corner and (0.5, 0.5) for the upper-right corner.

We also saw in the tutorial Texture Coordinates the effect when the length of the range of coordinates is greater than 1.0. For example, suppose we set the range of texture coordinates as [0.0, 2.0] for both the S and T coordinates. In this case, if the wrapping mode is GL_REPEAT, we get four full instances of the image map applied to the rectangle. We can achieve the same effect using a transformation and, in particular, a uniform scale by the factor 2.0. Following this scenario, if we set the wrapping to GL_CLAMP_TO_BORDER, we obtain one instance of the texture and an area around it to which the border color is applied. Further, if the environment mode is GL_DECAL and the alpha value of the border color is zero, then the underlying color of the geometry appears. We use in this tutorial GL_DECAL for the environment mode property of the texture object. Also, the alpha value of the border color is set to zero.