Adding textures to geometry can help make scenes more interesting. For example, we can make the floor in a room appear as wood by adding a wood grain image to the rectangular geometry of the floor. For our work, the image is provided with a bitmap (bmp) file. To become a texture, the bitmap must be read and stored in memory as a rectangular array of colors. The individual color points in the array are at times called TEXELS. In many applications, the texels replace the underlining color of the geometry and become the pixel colors. But in other applications such as games, it is useful to "remove" a selected color in the bitmap by allowing the underlying color show. The selected color is some times called the TRANSPARENCY COLOR. We see how this is accomplished in the tutorial Texture Transformations. OpenGL also provides for modulating (blending) the texels and geometry color in producing the pixels. An example of the latter is given in chapter 9.
To become texels, a bitmap, also called an image map, must be read and stored in memory. The Utils library that is provided with the tutorials contains the class ImageMap that handles this for us. The details on using the class are shown in the example ImageMap.
The focus of the tutorial is on texturing two dimensional objects and, in particular, texturing a rectangle. The example ImageMap illustrates texturing more general polygons.
There are several properties that must first be established before the texture can be applied. These properties include the number of dimensions (textures can also be 1 and 3 dimensions), the mode in which the texels are applied (replace, blend, modulate) and filtering. When using more than one texture in an application, it is useful to construct TEXTURE OBJECTS. We initialize each object with its respective properties and then "bind" the object as needed. Although this tutorial involves one texture, we still construct a texture object so as to illustrate the concept. After defining an object's texture properties, we establish how the texture is mapped to the geometry by associating textures coordinates with the vertices of the geometry.
The names given to the two-dimensional texture coordinates are S and T. The association is done inside the glBegin-glEnd pair where the vertices of the geometry are defined. In particular, prior to each call to glVertex, we call the function glTexCoord2f with the st-coordinates of the texel that we want to map to the vertex. The normal range of values for each texture coordinate is [0.0, 1.0]. By associating the texture coordinates (0.0, 0.0) with the lower-left corner of the rectangle and continuing the association with the texture coordinates (1.0, 0.0), (1.0, 1.0) and (0.0, 1.0) as we proceed around the corners of the rectangle, the rectangle will be covered by one instance of the image map. However, we can select other texture coordinates to create different effects as you experience with this tutorial.