Title: COMP471 Computer Graphics
1COMP471 Computer Graphics
2The Need
- Create complex appearance w/o much computational
effort
3Texture Def
- A detailed pattern repeated many times to tile a
given plane - A multidimensional image mapped to a multidim.
space.
4Texture 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
5Viewing
- 2D Texture Space
- 3D Model Space
- 2D Screen Space
parameterization
compound mapping
projection
6Texture 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
7Reading Textures
8Mapping Texture on Flat Surfaces and Quadric
Objects
9Cube
glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_
2D, m_aiTexNamesp_iFaceColor) draw cubes
face glDisable(GL_TEXTURE_2D)
10Sphere
glEnable(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)
11Spheremap
- Spheremap texture looks like reflection of a
sphere projected to a plane
180
eye
90
0
12Spheremap
- 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. - Maps center reflects back to eyes
13Generating Spheremap OpenGL
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILT
ER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP) glTexGeni(G
L_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP) glEnable
(GL_TEXTURE_GEN_S) glEnable(GL_TEXTURE_GEN_T) gl
TexEnvi(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) comput
eNormalsForYourObject() drawYourObject()
14References
- Jianxiang Dong Slides from Fall 2001