october 9, 2002serguei a. mokhov, [email protected] 1 comp471 – computer graphics opengl:...
TRANSCRIPT
October 9, 2002 Serguei A. Mokhov, [email protected]
1
COMP471 – Computer Graphics
OpenGL: Texture Mapping
October 9, 2002 Serguei A. Mokhov, [email protected]
2
The “Need”
• Create complex appearance w/o much computational effort
October 9, 2002 Serguei A. Mokhov, [email protected]
3
Texture Def
• A detailed pattern repeated many times to tile a given plane
• A multidimensional image mapped to a multidim. space.
October 9, 2002 Serguei A. Mokhov, [email protected]
4
Texture Mapping
• A technique to improve the appearance of the objects shaded with a light model
• Function of mapping an image onto a 3D surface
• Provide color details for complex surfaces
October 9, 2002 Serguei A. Mokhov, [email protected]
5
Viewing
• 2D Texture Space
• 3D Model Space
• 2D Screen Space
parameterization
projection
compound mapping
October 9, 2002 Serguei A. Mokhov, [email protected]
6
Texture in OpenGL
• Identified by an integer “name”• The procedure:
– Need to generate names first (glGenTextures())– Load images (see texture.h for BMPLoader for example)– Bind loaded binary image data to the integer name
(glBindTexture)– Set parameters (glTexParameter*())– Build mipmaps (e.g. gluBuild2DMipmaps())– When drawing an object
• Enable texturing• Specify a texture by its name• Disable texture mode
October 9, 2002 Serguei A. Mokhov, [email protected]
8
Mapping Texture on Flat Surfaces and Quadric Objects
• Cube
• Sphere
• Spheremap
October 9, 2002 Serguei A. Mokhov, [email protected]
9
Cube
glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, m_aiTexNames[p_iFaceColor]);
… draw cube’s face …
glDisable(GL_TEXTURE_2D);
October 9, 2002 Serguei A. Mokhov, [email protected]
10
SphereglEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, m_iTexName);
GLUquadricObj* l_poQuadric = gluNewQuadric();gluQuadricDrawStyle(l_poQuadric, GLU_FILL);gluQuadricNormals(l_poQuadric, GLU_SMOOTH);gluQuadricTexture(l_poQuadric, GL_TRUE); gluSphere(l_poQuadric, 0.5, 30, 30);gluDeleteQuadric(l_poQuadric);
glDisable(GL_TEXTURE_2D);
October 9, 2002 Serguei A. Mokhov, [email protected]
11
Spheremap
• Spheremap texture looks like reflection of a sphere projected to a plane
eye
0
90
180
October 9, 2002 Serguei A. Mokhov, [email protected]
12
Spheremap
• Spheremap texture is indexed from a reflection vector
• All computations are relative to the eye position• Texture looks like a reflection from a chrome
hemisphere• All mapping is done as reflection from
hemisphere.• Map’s center reflects back to eyes
October 9, 2002 Serguei A. Mokhov, [email protected]
13
Generating Spheremap: OpenGLglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);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);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
computeNormalsForYourObject();drawYourObject();
October 9, 2002 Serguei A. Mokhov, [email protected]
14
References
• Jianxiang Dong Slides from Fall 2001