Game Development Reference
In-Depth Information
Calculating texture coordinates for each vertex of each
polygon that uses a texture
When we draw with textures we need to inform OpenGL which part of the
2D texture to use on a polygon. We do this at the vertex level; for each
vertex that we draw we need to give a value for the texture coordinates.
These coordinates are values between 0.0 and 1.0 for both the width and
the height. To pass the value of the lower right coordinate of a bitmap to
OpenGL you use (1.0, 1.0) rather than (bitmap_width, bitmap_height).
Using this method a single bitmap can be wrapped around a highly
complex object. Generating the values for these coordinates can involve
quite a complex interface and we will look at various techniques in
Chapter 6.
Choosing a texture rendering mode
There are many ways that you can tell OpenGL to use your texture
objects. The different methods are set using glTexEnv*(). In the software
in this topic we always modulate the texture with a white polygon surface,
this is set up using:
You are advised to look through the documentation available with Visual
C++, do a search for glTexEnf in the MSDN help engine, or via the
OpenGL website ( to see how using different environ-
ment modes may work more effectively with your application.
Enabling textures
The last thing we need to do is enable textures using:
The function that draws the cube combines textured and untextured
surfaces. It is in the folder 'Chapter04' on the CD and is called
Search Nedrilad ::

Custom Search