And Some Extra Information From

Slides:



Advertisements
Similar presentations
TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
Advertisements

OpenGL Texture Mapping
Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =
Texture Mapping OpenGl and Implementation Details CS
CSC345: Advanced Graphics & Virtual Environments
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
OpenGL Texture Mapping April 16, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Basic Stragegy Three steps to applying a texture.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
UniS CS293 Graphics with Java and OpenGL Textures.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
Computer Graphics Texture Mapping Eriq Muhammad Adams
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Texture Mapping + Texture Object = Texture Mapped Object.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
2002 by Jim X. Chen: 1 Texture Lab At each rendered pixel, selected texels are used either to substitute for or to scale.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Texture Mapping. Example Mappings Mapping Techniques Consider the problem of rendering a sphere in the examples The geometry is very simple - a sphere.
Computer Graphics OpenGL - Texture mapping. OpenGL Texture mapping zTexture Mapping allows us to glue an image on polygons. In this method we can produce.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
An Interactive Introduction to OpenGL Programming Ed Angel
CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
Texture Mapping. 2 Motivation A typical modern graphics card can handle 10s of millions of polygons a second. How many individual blades of grass are.
OpenGL Texture Mapping. 2 Objectives Introduce the OpenGL texture functions and options.
Texture Mapping Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping Software College, Shandong University Instructor: Zhou Yuanfeng
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
October 9, 2002Serguei A. Mokhov, 1 COMP471 – Computer Graphics OpenGL: Texture Mapping.
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
Computer Graphics Bing-Yu Chen National Taiwan University.
CH6 Texture.
Texture Mapping and NURBS Week 7 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
第三课. Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation.
1 Chapter 7 Texture Mapping. 2 The Limits of Geometric Modeling Although graphics cards can render over 10 million polygons per second, that number is.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Texture Mapping Fall, 2016.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
OpenGL Texture Mapping
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
OpenGL Texture Mapping
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Chapters VIII Image Texturing
Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

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

The Quest for Visual Realism

Standard Quake 2 Model Rendering Texture key-frame with decal skin + Result Key-frame model geometry Decal skin

OpenGL Texture Mapping CPU DL Poly. Per Vertex Raster Frag FB Pixel Texture Apply a 1D, 2D, or 3D image to geometric primitives Uses of Texturing simulating materials reducing geometric complexity image warping reflections In this section, we’ll discuss texture ( sometimes also called image ) mapping. Texture mapping augments the colors specified for a geometric primitive with the colors stored in an image. An image can be a 1D, 2D, or 3D set of colors called texels. 2D textures will be used throughout the section for demonstrations, however, the processes described are identical for 1D and 3D textures. Some of the many uses of texture mapping include: simulating materials like wood, bricks or granite reducing the complexity ( number of polygons ) of a geometric object image processing techniques like image warping and rectification, rotation and scaling simulating reflective surfaces like mirrors or polished floors

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.

Reflection Sphere map:

Mapping a Texture Based on parametric texture coordinates CPU DL Poly. Per Vertex Raster Frag FB Pixel Texture Based on parametric texture coordinates glTexCoord*() specified at each vertex Texture Space Object Space t 1, 1 (s, t) = (0.2, 0.8) 0, 1 A a When you want to map a texture onto a geometric primitive, you need to provide texture coordinates. The glTexCoord*() call sets the current texture coordinates. Valid texture coordinates are between 0 and 1, for each texture dimension, and the default texture coordinate is ( 0, 0, 0, 1 ). If you pass fewer texture coordinates than the currently active texture mode ( for example, using glTexCoord1d() while GL_TEXTURE_2D is enabled ), the additionally required texture coordinates take on default values. c (0.4, 0.2) b B C (0.8, 0.4) 0, 0 1, 0 s

Texture Mapping y z x screen geometry t image s Textures are images that can be thought of as continuous and be one, two, three, or four dimensional. By convention, the coordinates of the image are s, t, r and q. Thus for the two dimensional image above, a point in the image is given by its (s, t) values with (0, 0) in the lower-left corner and (1, 1) in the top-right corner. A texture map for a two-dimensional geometric object in (x, y, z) world coordinates maps a point in (s, t) space to a corresponding point on the screen. image

Texture Mapping and the OpenGL Pipeline Images and geometry flow through separate pipelines that join at the rasterizer “complex” textures do not affect geometric complexity The advantage of texture mapping is that visual detail is in the image, not in the geometry. Thus, the complexity of an image does not affect the geometric pipeline (transformations, clipping) in OpenGL. Texture is added during rasterization where the geometric and pixel pipelines meet. geometry pipeline vertices pixel pipeline image rasterizer

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.

Texture Texture Image metrics must be power of 2 glEnable( GL_TEXTURE_2D );

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.

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 one 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.

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_UNSIGNED_BYTE, &mipmapImage32[0][0][0]); GL_UNPACK: from image to memory Alignment: better fit memory boundary

Texture Mapping y z x screen geometry t image s Textures are images that can be thought of as continuous and be one, two, three, or four dimensional. By convention, the coordinates of the image are s, t, r and q. Thus for the two dimensional image above, a point in the image is given by its (s, t) values with (0, 0) in the lower-left corner and (1, 1) in the top-right corner. A texture map for a two-dimensional geometric object in (x, y, z) world coordinates maps a point in (s, t) space to a corresponding point on the screen. image

Anti-aliasing Techniques

Mip-Mapping Concept

W/O MIP W

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*

Mip-Mapping Example: 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

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 );

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

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.

The following lines are examples of how to use glTexParameter 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);

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.

glTexEnv() void glTexEnv{if}[v](GLenum target, GLenum pname, TYPE param); 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.

Why? There are two cases: Ct= white or Ct=black Ct=white C=Cc*Ct=Green C=Cf=white

GL_DECAL GL_MODULATE GL_BLEND Non-textured Shaded Teapot See texgen.c

More Examples and Experiments about glTexEnv() Texture mapping Demo: is Available on our web Soon!!

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

Texture Object Naming a texture object void glGenTextures(GLsizei n, GLuint *textureNames); glIsTexture() determines if a texture name is actually in use Bind a texture name to a texture object void glBindTexture(GLenum target, GLuint textureName); Cleaning up texture objects void glDeleteTextures(GLsizei n, const GLuint *textureNames);

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); }

Step 4: Assigning Texture Coordinates As you draw your texture-mapped scene, you must provide both object coordinates and texture coordinates for each vertex. Texture coordinates can comprise one, two, three, or four coordinates. 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)

Mapping a Texture Based on parametric texture coordinates CPU DL Poly. Per Vertex Raster Frag FB Pixel Texture Based on parametric texture coordinates glTexCoord*() specified at each vertex Texture Space Object Space t 1, 1 (s, t) = (0.2, 0.8) 0, 1 A a When you want to map a texture onto a geometric primitive, you need to provide texture coordinates. The glTexCoord*() call sets the current texture coordinates. Valid texture coordinates are between 0 and 1, for each texture dimension, and the default texture coordinate is ( 0, 0, 0, 1 ). If you pass fewer texture coordinates than the currently active texture mode ( for example, using glTexCoord1d() while GL_TEXTURE_2D is enabled ), the additionally required texture coordinates take on default values. c (0.4, 0.2) b B C (0.8, 0.4) 0, 0 1, 0 s

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();

Transform Texture Texture Matrix Stack glMatrixMode( GL_TEXTURE ); Translate, scale, rotation Similar to VRML to transform that “cutting frame”.

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

Repeating and Clamping Texture Clamping a texture Repeating and Clamping a texture

Texture Parameters

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);

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 either 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 };

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

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_FILTER,          GL_LINEAR); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER,          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_LINEAR);     glTexGenfv(GL_S, GL_OBJECT_PLANE, sgenparams);

Automatic Texture-Coordinate Generation Sphere map:

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.

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.

Automatic Texture-Coordinate Generation Environment Mapping To automatically generate the texture coordinates 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.

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

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.

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);

gluSphere(quadratic,Radius,32,32);