Open GL Super Bible:Texture Mapping
To access the contents, click the chapter and section titles.
Open GL Super Bible
(Publisher: Macmillan Computer Publishing)
Author(s): Waite group Press
ISBN: 1571690735
Publication Date: 08/01/96
Previous
Table of Contents
Next
Drawing Textured Polygons
Once you have defined a texture, you still have to enable texturing. To enable 1D texturing, youłd use the following:
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_1D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
The glEnable call enables 1D texturing. If you forget to enable texturing, none of your polygons will be textured! The glTexEnvi function sets texturing to “decal" mode, meaning that images are overlaid directly upon the polygons.
Other texturing modes are listed in Table 12-2.
Table 12-2 Texture Modes for GL_TEXTURE_ENV_MODE
Mode
Description
GL_MODULATE
Texture pixels “filter" existing pixel colors on the screen.
GL_DECAL
Texture pixels replace existing pixels on the screen.
GL_BLEND
Texture pixels “filter" existing pixels colors and are combined with a constant color.
The GL_MODULATE texture mode multiplies the current texture color (or luminance) by the color on the screen. For one-component (luminance) textures, this translates into a brightness filter that will vary the brightness of the screen image based upon the texture image. For three-component (RGB) textures, you can generate “colored lens filter" effects.
Unlike GL_MODULATE texturing, GL_BLEND texturing allows you to blend a constant color into the scene based upon the texture image. Youłd use GL_BLEND texturing for things like clouds; the constant color would be off-white, and the texture image would be of a cloud.
Once you have defined the texturing mode to use, you can then proceed with the drawing of your polygons. Listing 12-3 shows how to draw the rainbow in Figure 12-1.
Listing 12-3 Drawing a 1D textured rainbow
glEnable(GL_TEXTURE_1D);
glCallList(RainbowTexture);
glBegin(GL_QUAD_STRIP);
for (th = 0.0; th <= M_PI; th += (0.03125 * M_PI))
{
/*
* Bottom edge of rainbow
*/
x = cos(th) * 50.0;
y= sin(th) * 50.0;
z = -50.0;
glTexCoord1f(0.0);
glVertex3f(x, y, z);
/*
* Top edge of rainbow
*/
x = cos(th) * 55.0;
y = sin(th) * 55.0;
z = -50.0;
glTexCoord1f(1.0);
glVertex3f(x, y, z);
};
glEnd();
To position the ROY-G-BIV texture on the rainbow, you call glTexCoord. For 1D textures, you call one of the glTexCoord1f, glTexCoord1d, glTexCoord1s, or glTexCoord1i functions. A value of 0.0 represents the leftmost pixel in the image, and 1.0 represents the rightmost pixel. Values outside this range are handled differently depending on the value of the GL_TEXTURE_WRAP_S parameter. If GL_TEXTURE_WRAP_S is set to GL_CLAMP (the default), then texture coordinates are restricted to a range of 0.0 to 1.0, inclusive. When a polygon strays from the texture image, it is drawn using the color(s) along the texture imagełs edges (see Figure 12-3) or the texture image border colors, if defined. Texture coordinates are traditionally referred to as S and T, or (s,t) instead of X and Y.
Figure 12-3 GL_CLAMP textures
If you use GL_REPEAT instead, the texture image is tiled over the polygon. Texture coordinates are used modulo 1.0that is, the texture image repeats at regular intervals. GL_REPEAT texturing can be used to reduce the size of texture images on repetitive surfaces. The challenge with these kinds of textures is to make the edges of each tile blend into the next.
Automatically Generating Texture Coordinates: Generating texture coordinates can be a tedious task. Later in this chapter youłll learn about the glTexGen functions that can generate these coordinates automatically for you.
Previous
Table of Contents
Next
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
390 393390 (2)III CSK 388 06 1390 394 ezvsba2wgoc7nualallnxgc6cwsmpxxds5ar7ni08 (390)103907 kierownik firmy sprzatajacej11 (390)385 388więcej podobnych podstron