1. Set up texture mapping:
void
glEnable(GL_TEXTURE_2D); - enables 2D texturing
void
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- sets texture environment parameters: GL_MODULATE specifies
to blend texture with the current color of the object. Use GL_DECAL or white
color for texture showing.
2. Bind texture to a texture object: achieved by
void
glBindTexture(GLenum target, GLuint texture);
binds a named texture to a texturing target: specify which
texture to use when multiple textures are in use.
For this to work, the texture parameter has to be bound to a
specific texture object. This requires loading a texture file (bitmap, giff,
jpg etc.) through some graphics file reader, e.g.
LoadTexture("earth.bmp",
earthTexture);
can be followed by
glBindTexture(GL_TEXTURE_2D,
earthTexture);
3. Map texture to polygons:
this is achieved by
void
glTexCoord2f(GLfloat s, GLfloat t) -
specifies the s, t texture coordinates that map to a particular
vertex of the surface polygon. Typically followed by a vertex definition (glVertex3f).
The typical calling sequence for a textured object might
look like:
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, GL_MODULATE);
gluQuadricTexture(gluSpherePtr,
true);
glBindTexture(GL_TEXTURE_2D,
earthTexture);
gluSphere(gluSpherePtr,
size, stacks, slices);