Texture Transformations

Transformations - translation, rotation, and scaling - can be applied to textures, similar to how they are applied to geometry.

The exact same OpenGL function calls are used. The only difference is that the matrix mode is changed to GL_TEXTURE.

    glMatrixMode(GL_TEXTURE);
     glTranslatef(0.1, 0.05, 0);
    glMatrixMode(GL_MODELVIEW);

Setting the matrix mode to GL_TEXTURE means that any subsequent transformation calls will be applied to texture coordinates, rather than vertex coordinates.

We switch the matrix mode back to the "default" of GL_MODELVIEW when we're done, so as to not adversely affect other code.

Examples:

Note that texture coordinates are generally 2 dimensional, so we only translate and scale in the X & Y directions (called U & V in textures), and rotate around the Z axis.




The same effect can be achieved by dynamically changing the texture coordinates directly.

The advantages are: GL transformation functions simplify things and take care of the math, and transformations can be applied to objects where we might not have direct control of the texture coordinates.

Example: texSphere.cpp



next