Texture Mapping From RedBook Chapter 9 And Some Extra Information From Tong-Yee Lee.

83
Texture Mapping From RedBook Chapter 9 And Some Extra Information From www.opengl.org Tong-Yee Lee

Transcript of Texture Mapping From RedBook Chapter 9 And Some Extra Information From Tong-Yee Lee.

Page 1: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture Mapping

From RedBook Chapter 9And Some Extra Information From

www.opengl.org

Tong-Yee Lee

Page 2: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

The Quest for Visual Realism

Page 3: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Standard Quake 2Model Rendering

• Texture key-frame with decal skin

++++

ResultResultResultResult

Key-frameKey-framemodelmodelgeometrygeometry

Key-frameKey-framemodelmodelgeometrygeometry DecalDecal

skinskinDecalDecalskinskin

Page 4: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

• Apply a 1D, 2D, or 3D image to geometric primitives

• Uses of Texturing– simulating materials– reducing geometric complexity– image warping

– reflections

• Apply a 1D, 2D, or 3D image to geometric primitives

• Uses of Texturing– simulating materials– reducing geometric complexity– image warping

– reflections

OpenGL TextureMappingCPU

CPUDLDL

Poly.Poly. Per

Vertex

PerVertex

RasterRaster

FragFrag

FBFB

PixelPixel

TextureTexture

Page 5: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Environment Maps If, instead of using the ray from the surface point to the projected texture's center, we used the direction of the reflected ray to index a texture map. We can simulate reflections. This approach is not completely accurate. It assumes that all reflected rays begin from the same point, and that all objects in the scene are the same distance from that point.

Page 6: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Reflection

• Sphere map:

Page 7: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

• Based on parametric texture coordinates• glTexCoord*() specified at each vertex

s

t 1, 10, 1

0, 0 1, 0

(s, t) = (0.2, 0.8)

(0.4, 0.2)

(0.8, 0.4)

A

B C

a

bc

Texture Space Object Space

Mapping aTextureCPU

CPUDLDL

Poly.Poly. Per

Vertex

PerVertex

RasterRaster

FragFrag

FBFB

PixelPixel

TextureTexture

Page 8: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture Mapping

s

t

x

y

z

image

geometry screen

Page 9: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture Mapping and the OpenGL Pipeline

geometry pipelinevertices

pixel pipelineimage

rasterizer

• Images and geometry flow through separate pipelines that join at the rasterizer– “complex” textures do not affect geometric co

mplexity

Page 10: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Steps in Texture Mapping

• Specify the texture• Indicate how the texture is to be applied to each

pixel. • Enable texture mapping• Draw the scene, supplying both texture and

geometric coordinates• Keep in mind that texture mapping works only in

RGB mode; the results in color-index mode are undefined.

Page 11: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture

• Texture Image metrics must be power of 2

• glEnable( GL_TEXTURE_2D );

Page 12: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Step 1: Specifying Texture

• A texture is usually thought of as being two-dimensional, like most images, but it can also be one-dimensional. The data describing a texture can consist of one, two, three, or four elements per texel, representing anything from a modulation constant to an (R, G, B, A) quadruple.

• glTexImage2D() defines a two-dimensional texture.

• glTexImage1D(), is described in "One-Dimensional Textures.

Page 13: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

glTexImage2D()

• glTexImage2D(GLenum target, GLint level, GLint internal_components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const Glvoid *pixels);

– glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage32);

– The target parameter must be set to the constant GL_TEXTURE_2D– You use the level parameter if you're supplying multiple resolutions of the texture map; with only on

e resolution, level should be 0.– The next parameter, internal_components, is an integer from 1 to 4 indicating which of the R, G, B,

and A components are selected for use in modulating or blending.– The width and height components must be a power of 2– border indicates the width of the border, which is usually zero.– The format and type parameters describe the format and data type of the texture image data.

• The format parameter can be GL_COLOR_INDEX, GL_RGB, GL_RGBA,GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_LUMINANCE, or GL_LUMINANCE_ALPHA

• the type parameter can be GL_BYTE, GL_UNSIGNED_BYTE,• GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, or GL_BITMAP.

– pixels contains the texture-image data. This data describes the texture image itself as well as its border.

Page 14: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

• It describes how the bitmap data is stored in computer memory

• Ex: – glPixelStorei(GL_UNPACK_ALIGNMENT, 1); – glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, GL_RGB, GL_UNSIGN

ED_BYTE, &mipmapImage32[0][0][0]); • GL_UNPACK: from image to memory• Alignment: better fit memory boundar

y

Page 15: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 16: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture Mapping

s

t

x

y

z

image

geometry screen

Page 17: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 18: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Anti-aliasing Techniques

Page 19: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Mip-Mapping Concept

Page 20: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

W/O

W

MIP

Page 21: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Multiple Levels of Detail(Mip-Mapping )

• In a dynamic scene, for example, as a textured object moves farther from the viewpoint, the texture map must decrease in size along with the size of the projected image.

• Specified in the “level” parameter in glTexImage2D*

Page 22: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Mip-MappingExample:glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0,

GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage32);

glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage16);

glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage8);

glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage4);

glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage2);

glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, mipmapImage1);

Note: you need to create multiple resolutions by yourself

Page 23: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Mip-Mapping

• Using GLU helper– int gluBuild2DMipmaps(GLenum target, GLint

components, GLint width,GLint height, GLenum format, GLenum type, void *data);

• gluBuild2DMipmaps( GL_TEXTURE_2D, 3, 32, 32, GL_RGB, GL_UNSIGNED_BYTE, texImage32 );

Page 24: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Scale Texture Image

• int gluScaleImage(GLenum format, GLint widthin, GLint heightin,GLenum typein, const void *datain, GLint widthout,GLint heightout, GLenum typeout, void *dataout);

• Assuming that you have constructed the level 0, or highest-resolution map, the routines gluBuild1DMipmaps() and gluBuild2DMipmaps() construct and define the pyramid of mipmaps down to a resolution of 1 × 1 (or 1, for one-dimensional texture maps). Both these routines require that the original image already be suitable for a texture map, namely that its dimensions must be powers of 2. Most scanned images don't satisfy this property, so you have to scale the incoming image to some appropriate size

Page 25: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Control Filtering• Texture maps are square or rectangular, but after being mapped to a

polygon or surface and transformed into screen coordinates, the individual texels of a texture rarely correspond to individual pixels of the final screen image.

• Depending on the transformations used and the texture mapping applied, a single pixel on the screen can correspond to anything from a tiny portion of a texel (magnification) to a large collection of texels (minification), as shown in Figure 9-4 .

• In either case, it's unclear exactly which texel values should be used and how they should be averaged or interpolated. Consequently, OpenGL allows you to specify any of several filtering options to determine these calculations. The options provide different trade-offs between speed and image quality. Also, you can specify the filtering methods for magnification and minification independently.

Page 26: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 27: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 28: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

•The following lines are examples of how to use glTexParameter*() to specify the magnification and minification filtering methods:

–glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST); –glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

Page 29: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 30: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 31: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Step 2:Indicate How the Texture Is to Be Applied to Each Pixel

• You can choose any of three possible functions for computing the final RGBA value from the fragment color and the texture-image data. (decal or modulate or blend)

• One possibility is to simply use the texture color as the final color; this is the decal mode, in which the texture is painted on top of the fragment, just as a decal would be applied.

• Another method is to use the texture to modulate, or scale, the fragment's color; this technique is useful for combining the effects of lighting with texturing.

• Finally, a constant color can be blended with that of the fragment, based on the texture value.

Page 32: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

glTexEnv()• void glTexEnv{if}[v](GLenum target, GLenum pname, TYPE para

m);– Sets the current texturing function. target must be GL_TEXTURE_ENV. – If pname is GL_TEXTURE_ENV_MODE, param can be GL_DECAL,

GL_MODULATE, or GL_BLEND, to specify how texture values are to be combined with the color values of the fragment being processed.

– In decal mode and with a three-component texture, the texture's colors replace the fragment's colors.

– With either of the other modes or with a four-component texture, the final color is a combination of the texture's and the fragment's values.

– If pname is GL_TEXTURE_ENV_COLOR, param is an array of four floating-point values representing R, G, B, and A components. These values are used only if the GL_BLEND texture function has been specified as well.

Page 33: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 34: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 35: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 36: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

There are two cases:

Ct= white or Ct=black

(1)Ct=white C=Cc*Ct=Green(2) Ct=black C=Cf=white

Why?

Page 37: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Non-textured Shaded Teapot

See texgen.c

GL_DECAL GL_MODULATE GL_BLEND

Page 38: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

More Examples and Experiments about glTexEnv()

Texture mappingDemo: is

Available on our webSoon!!

Page 39: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Step 3: Enable Texture

• Operate texture as an object

• Steps to use texture object– Generate texture names– Bind texture objects to texture data &

parameters– You can set priority for each texture object– Rebind the texture objects for applying

Page 40: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture Object

• Naming a texture object– void glGenTextures(GLsizei n, GLuint *texture

Names);

• glIsTexture() determines if a texture name is actually in use

• Bind a texture name to a texture object– void glBindTexture(GLenum target, GLuint tex

tureName);• Cleaning up texture objects

– void glDeleteTextures(GLsizei n, const GLuint *textureNames);

Page 41: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture Object

static GLuint texName[1]; void init(void){

…..glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, texName); glBindTexture(GL_TEXTURE_2D, texName[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage32 );

glEnable(GL_TEXTURE_2D); }

Page 42: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Step 4: Assigning Texture Coordinates

• As you draw your texture-mapped scene, you must provide both object coordinates and texture coordinates for ea

ch vertex. • Texture coordinates can comprise one, two, three, or four c

oordinates. They're usually referred to as the s, t, r, and q coordinates to distinguish them from object coordinates (x, y, z, and w)

• void glTexCoord{1234}{sifd}{v}(TYPEcoords)

Page 43: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

• Based on parametric texture coordinates• glTexCoord*() specified at each vertex

s

t 1, 10, 1

0, 0 1, 0

(s, t) = (0.2, 0.8)

(0.4, 0.2)

(0.8, 0.4)

A

B C

a

bc

Texture Space Object Space

Mapping aTextureCPU

CPUDLDL

Poly.Poly. Per

Vertex

PerVertex

RasterRaster

FragFrag

FBFB

PixelPixel

TextureTexture

Page 44: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Example

glBegin(GL_QUADS);glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); glTexCoord2f(0.0, 8.0); glVertex3f(-2.0, 1.0, 0.0); glTexCoord2f(8.0, 8.0); glVertex3f(2000.0, 1.0, -6000.0); glTexCoord2f(8.0, 0.0); glVertex3f(2000.0, -1.0, -6000.0); glEnd();

Page 45: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Transform Texture

• Texture Matrix Stack– glMatrixMode( GL_TEXTURE );– Translate, scale, rotation– Similar to VRML to transform that “cutting fr

ame”.

Page 46: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 47: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 48: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 49: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 50: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 51: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Repeating and Clamping Texture

• Using glTexParameter*(…);– glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_

REPEAT);

– glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

• Repeating a texture

Page 52: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Repeating and Clamping Texture

• Clamping a texture

• Repeating and Clamping a texture

Page 53: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Texture Parameters

Page 54: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 55: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 56: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 57: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Automatic Texture-Coordinate Generation

• You can use texture mapping to make contours on your models or to simulate the reflections from an arbitrary environment on a shiny model.

• To achieve these effects, let OpenGL automatically generate the texture coordinates for you, rather than explicitly assigning them with glTexCoord*().

• Actually, the mechanism for automatic texture-coordinate generation is useful for many different applications such as showing contours and environment mapping.

• To generate texture coordinates automatically, use the command glTexGen(). void glTexGen{ifd}{v}(GLenum coord, GLenum pname, TYPEparam);

Page 58: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 59: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Automatic Texture-Coordinate

Generation

• void glTexGen{ifd}(GLenum coord, GLenum pname, TYPEparam);void glTexGen{ifd}v(GLenum coord, GLenum pname, TYPE *param); – coord can be GL_S, GL_T, GL_R, GL_Q– If pname is GL_TEXTURE_GEN_MODE, param is eit

her GL_OBJECT_LINEAR, GL_EYE_LINEAR, GL_SPHERE_MAP

– If pname is GL_OBJECT_PLANE or GL_EYE_PLANE, param is the plane coefficients array

• Ex: – plane equation is 1x + 2y + 3z = 0 – GLfloat plane[4] = { 1, 2, 3, 0 };

Page 60: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 61: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 62: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Automatic Texture-Coordinate Generation

(a) The texture contour stripes are parallel to the plane x = 0, (GL_OBJECT_LINEAR). – As the object moves, the texture appears to be attached to it.

(b) A different planar equation (x + y + z = 0) is used, so the stripes have a different orientation.

(c) The texture coordinates are calculated relative to eye coordinates and hence aren't fixed to the object (GL_EYE_LINEAR).

– As the object moves, it appears to "swim" through the texture

• REDBOOK• Texgen2.c

Page 63: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Example• GLfloat sgenparams[] = {1.0, 0.0, 0.0, 0.0}; • loadStripeImage(); • glPixelStorei(GL_UNPACK_ALIGNMENT, 1); • glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_

MODULATE); • glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S,

GL_REPEAT);• glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTE

R, GL_LINEAR);• glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTE

R, GL_LINEAR); • glTexImage1D(GL_TEXTURE_1D, 0, 3, stripeImageWidth, 0,

GL_RGB, GL_UNSIGNED_BYTE, stripeImage); • glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LIN

EAR); • glTexGenfv(GL_S, GL_OBJECT_PLANE, sgenparams);

Page 64: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 65: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 66: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 67: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Automatic Texture-Coordinate Generation

• Sphere map:

Page 68: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 69: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Environment Mapping• The goal of environment mapping is to render an object as if it were perfectly reflective,

so that the colors on its surface are those reflected to the eye from its surroundings• Example: if you look at a perfectly polished, perfectly reflective silver object in a

room, you see the walls, floor, and other objects in the room reflected off the object. The objects whose reflections you see depend on the position of your eye and on the position and surface angles of the silver object.

• Environment mapping is an approximation based on the assumption that the items in the environment are far away compared to the surfaces of the shiny object - that is, it's a small object in a large room. With this assumption, to find the color of a point on the surface, take the ray from the eye to the surface, and reflect the ray off the surface. The direction of the reflected ray completely determines the color to be painted there. Encoding a color for each direction on a flat texture map is equivalent to putting a polished perfect sphere in the middle of the environment and taking a picture of it with a camera that has a lens with a very long focal length placed far away. Mathematically, the lens has an infinite focal length and the camera is infinitely far away. The encoding therefore covers a circular region of the texture map, tangent to the top, bottom, left, and right edges of the map. The texture values outside the circle make no difference, as they are never accessed in environment mapping.

Page 70: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Sphere-mapping

• Sphere-mapping provides an interesting way of mapping a single-image texture onto the surface of an object that allows for view-dependent effects such as reflections, refractions, and even outlining and other non-photorealistic effects. More specifically, sphere-mapping maps all "reflected" vector directions intoa single image (actually into the largest circle that will fit in the texture image). The problem then becomes determining the relationship between the (s,t) texture coordinates, the texture-map, the reflection vector, the eye, and a particular vertex for which we want to find tex-coords for.

Page 71: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 72: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 73: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 74: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Automatic Texture-Coordinate Generation

• Environment Mapping– To automatically generate the texture coordinat

es to support environment mapping, use this code in your program:

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S);glEnable(GL_TEXTURE_GEN_T);

– The GL_SPHERE_MAP constant creates the proper texture coordinates for the environment mapping.

Page 75: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

Our final scene will contain two different 'objects'. The first one will be a '' shaped object that will use dynamic coordinates to simulate a 'waterfall' effect. The second will be an environmentally mapped torus.

Three shots of scene Original Texture

Page 76: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 77: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 78: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 79: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 80: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

NewQuadric• GLUquadricObj *quadratic; // Storage For Our

//Quadratic Objects ( NEW )• quadobject = gluNewQuadric (); • gluQuadricDrawStyle (quadobject, GLU_FILL); • gluQuadricNormals (quadobject, GLU_SMOOTH); • gluQuadricTexture(quadobject,GL_TRUE);//Generates

Texture coordinates • glBindTexture(GL_TEXTURE_2D, texName[0]); • gluSphere(quadobject,r,25,20);

– As you can see the QuadricTexture is called and then the BindTexture is called to bind the texture to the Sphere.

Page 81: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

NewQuadric

• gluCylinder(quadratic,base_R,top_R,height,32,32);

• gluDisk(quadratic,inner_R,outer_R,32,32);

// Draw A Disc (CD Shape) With An Inner Radius Of 0.5,

• gluSphere(quadratic,Radius,32,32);

Page 82: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.
Page 83: Texture Mapping From RedBook Chapter 9 And Some Extra Information From   Tong-Yee Lee.

•gluSphere(quadratic,Radius,32,32);