Open GL Super Bible:Texture Mapping
To access the contents, click the chapter and section titles.
Open GL Super Bible
(Publisher: Macmillan Computer Publishing)
Author(s): Waite group Press
ISBN: 1571690735
Publication Date: 08/01/96
Previous
Table of Contents
Next
Chapter 12Texture Mapping
What youłll learn in this chapter:
How to
Functions Youłll Use
Drape images onto polygons (texture mapping)
glTexImage1D/glTexImage2D
Use .BMP files as textures
TextureLoadBitmap/TextureLoadMipmapy
Use automatic texture coordinate generation
glTexGen
Texture mapping is probably the most significant advance in computer graphics in the last ten years. OpenGL provides texture image mapping functions that fit images onto polygons in your scene. How those images are put onto the polygons is up to you.
Texture mapping is used in games, including DOOM, for realistic images of rooms and monsters. Unlike OpenGL, these games use a texturing method called raycasting to map texture images onto polygons. Though raycasting is much faster on standard graphics cards than the texture mapping provided by OpenGL, it is also limited to flat surfaces in a 2D plane. That is, you canłt look up or down. Texture mapping in OpenGL doesnłt have this limitation, but you can expect it to work more slowly on standard graphics cards.
The good news is that some newer, affordable 3D graphics cards support OpenGL and hardware texturing. When a board supports hardware texture mapping, your CPU doesnłt have to do all the texture mapping calculations and preparationthe graphics card does it for you.
The examples in this chapter will run on any Windows-compatible graphics card. If your graphics card supports 16- or 24-bit “true color" displays, youÅ‚ll want to use them. Besides better-looking scenes, youÅ‚ll find that the 16- and 24-bit modes are actually faster.
The Basics of Texture Mapping
Texture mapping in OpenGL is fairly straightforward. To begin with, every texture is an image of some sort.
A 1D texture is an image with width but no height, or vise versa; 1D textures are a single pixel wide or high. You might think that 1D textures arenÅ‚t very useful, but in fact they can take the place of more conventional color-shading techniques and accelerate rendering in the process! Figure 12-1 shows a 1D “ROY-G-BIV" (Red, Orange, Yellow - Green - Blue, Indigo, Violet) texture to display a rainbow. The texture image is a line of pixels (color values) covering the color spectrum seen in a rainbow. The equivalent nontextured scene would contain seven times the polygons of the textured one and require much more rendering time.
Figure 12-1 A 1D textured rainbow
A 2D texture is an image that is more than 1 pixel wide and high and is generally loaded from a Windows .BMP file. Two-dimensional textures are commonly used to replace complex surface geometry (lots of polygons) on buildings, trees, and so forth. These 2D textures can also be used to add realistic background details, like the clouds in the sky in Figure 12-2.
Figure 12-2 A 2D sky texture and the resulting scene
The 1D and 2D textures youłve seen so far are composed of RGB color values. Textures can also be composed of color indices or luminance (gray) levels, and can include alpha (transparency) values. The latter is useful for defining natural objects such as trees, because the alpha value can be used to make the tree visible but let the background show through. Youłll learn more about this in Chapter 16.
Some hardware also supports 3D (volume) textures with OpenGL. Volume textures are used for viewing CAT, MRI, and other 3D “scans." Unfortunately, even a small 256 x 256 x 256 grayscale texture image will need a whopping 16 MB of memory. Currently an extension to OpenGL, 3D texturing may be included as a required feature in the OpenGL 1.1 specification.
Defining Texture Images
Naturally, you must define a texture image before you can draw textured polygons in OpenGL. Texture images follow the same storage rules as bitmaps (discussed in Chapter 11).
A Note About Texture Images: The OpenGL standard requires that texture imagesł dimensions must be a power of 2. Texture images can also have 1 or 2 border pixels around their edges to define the color of polygons that fall outside the texture image.
Previous
Table of Contents
Next
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
381 385 bkxxfouzvuxv2ywm5ifjqi5m2dmkizz5w7ktqni10 (385)385 Poprawiamy błedy w zapisach księgowych385 388383 386385 388demo cgi 38306 (383)19 (385)więcej podobnych podstron