C481 B581 Computer Graphics
Dana Vrajitoru
Texture Mapping
Texture
-
Modify the initial color of the point to create texture effects.
-
Projected texture - Project each 3D point Q to a 2D point P in an pixmap,
also called the texture.
-
Assign to Q the color of P before applying any light algorithm.
-
Can also interpolate between the original color of the point and the color
of the texture.
-
Question: how to tile the texture image on the 3D object smoothly.
-
Texture mapping - Same as before, but perturb the texture map by
a function. Simulates rough looking surface.
-
Solid texture - Compute the texture map by an analytical function.
Wood, stone, marble, checker board, complex fabric patterns, etc.
Texture in OpenGL
-
Textures can be in 1D, 2D, or 3D.
-
Each of them is stored in an array of bytes of size 3*nr of pixels.
-
For the 1D texture, size=length.
-
For the 2D texture, size=width*height.
-
For the 3D texture, size=width*height*depth.
-
Each dimension must be a power of 2.
Texture from a Bitmap File
-
The bitmap file must have both width and height equal to a power of 2.
-
The BMP file is binary, and has the following structure:
-
Bitmap File Header – specify that the file is a bitmap
-
Bitmap Info – contains the width and height
-
Pixel data - 3b per pixel - bgr (rgb upside down)
Applying the Texture
-
Enable - disable the texture:
glEnable(GL_TEXTURE_2D); //1D, 3D
glDisable(GL_TEXTURE_2D);
-
Create the texture out of the array of points:
glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,buffer);
-
Parameters: target, level, components, width, height, border, format, type,
*pixels.
Texture Mode
-
Defines the interaction of the texture with current light and color.
-
GL_MODULATE - light properties apply to the texture.
-
GL_DECAL - light and color don't affect the texture.
-
GL_BLEND - mixes the currently active
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
Texture Filters
-
2 types of filters: minification, for polygons smaller than the image,
and magnification, for polygons larger than the image.
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
-
Filters: GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, a combination
of each of them and MIPMAP
-
Mipmaped textures: based on several images, can chose the one that is appropriate
for the level of detail.
Texture Coordinates
-
Associates a particular location in the texture with a vertex.
-
For a 2D texture, the coordinates are denoted by s and t. Both of them
are between 0.0 and 1.0.
glTexCoord2d(0.0, 1.0);
-
The glTexCoord2d must be used before the vertex it applies to.
Example of source code: teapot_texture.cc,
and some bitmap files it can use: tiles.bmp, pattern.bmp,
marble.bmp,
liquid.bmp,
bricks.bmp.
Snapshots from this program:
GL_DECAL option for the texture mode, marble bitmap.
GL_DECAL option for the texture mode, pattern bitmap.
GL_MODULATE option for the texture mode, marble bitmap.
GL_BLEND option for the texture mode, applied to the marble bitmap
with a previously defined purple color.
GL_BLEND option for the texture mode, applied to the tiles bitmap with
a previously defined purple color.
Another example with the texture applied to a quadric object:
texture_quadric.cc
Last modified: April 12, 2005.
danav@cs.iusb.edu.