⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter09.html

📁 OpenGl红宝书
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-2">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.07 [en] (Win98; I) [Netscape]">
   <META NAME="Author" CONTENT="Goran UnreaL Krajnovic">
   <TITLE>Chapter 9 - OpenGL Programming Guide (Addison-Wesley Publishing Company)</TITLE>
</HEAD>
<BODY BGCOLOR="#EFEFEF" LINK="#0000FF" VLINK="#551A8B" ALINK="#FF0000">

<DIV ALIGN=right><IMG SRC="figures/SGI_ID.gif" ALT="Silicon Graphics" NOSAVE HEIGHT=43 WIDTH=151 ALIGN=TEXTTOP></DIV>

<PRE>
</PRE>

<HR>
<H1>
Chapter 9<BR>
Texture Mapping</H1>
<B>Chapter Objectives</B>
<P>After reading this chapter, you'll be able to do the following:
<UL>Understand what texture mapping can add to your scene
<BR>&nbsp;
<P>Specify a texture map and how its coordinates relate to those of the
objects in your scene
<BR>&nbsp;
<P>Control how a texture image is filtered as it's applied to a fragment
<BR>&nbsp;
<P>Specify how the color values in the image combine with those of the
fragment to which it's being applied
<BR>&nbsp;
<P>Use automatic texture coordinate generation to produce effects like
contour maps and environment maps</UL>
So far in this guide, every geometric primitive has been drawn as either
a solid color or smoothly shaded between the colors at its vertices - that
is, they've been drawn without texture mapping. If you want to draw a large
brick wall without texture mapping, for example, each brick must be drawn
as a separate polygon. Without texturing, a large flat wall - which is
really a single rectangle - might require thousands of individual bricks,
and even then the bricks would appear too smooth and regular to be realistic.
<P>Texture mapping allows you to glue an image of a brick wall (obtained,
perhaps, by scanning in a photograph of a real wall) to a polygon, and
to draw the entire wall as a single polygon. Texture mapping ensures that
all the right things happen as the polygon is transformed and rendered:
When the wall is viewed in perspective, for example, the bricks decrease
in size along with the wall as the wall gets farther from the viewpoint.
Other uses for texture mapping include vegetation to be textured on large
polygons representing the ground for a flight simulator; wallpaper patterns;
and textures that make polygons appear to be made of natural substances
such as marble, wood, or cloth. The possibilities are endless. Although
it's most natural to think of applying textures to polygons, textures can
be applied to all primitives - points, lines, polygons, bitmaps, and images.
Plates 6, 8, 18-21, 24-27, and 29-31 all demonstrate the use of textures.
<P>Because there are so many possibilities, texture mapping is a fairly
large, complex subject, and you must make several programming choices when
using it. For instance, you can map textures to surfaces made of a set
of polygons or to curved surfaces, and you can repeat a texture in one
or both directions to cover the surface. A texture can even be one-dimensional.
In addition, you can automatically map a texture onto an object in such
a way that the texture indicates contours or other properties of the item
being viewed. Shiny objects can be textured so that they appear as if they
were in the center of a room or other environment, reflecting the surroundings
off their surfaces. Finally, a texture can be applied to a surface in different
ways. It can be painted on directly (like a decal placed on a surface),
it can be used to modulate the color the surface would have been painted
otherwise, or it can be used to blend a texture color with the surface
color. If this is your first exposure to texture mapping, you might find
that the discussion in this chapter moves fairly quickly. As an additional
reference, you might look at the chapter on texture mapping in <I>Fundamentals
of Three-Dimensional Computer Graphics</I> by Alan Watt (Reading, Mass.:
Addison-Wesley, 1990).
<P>Textures are simply rectangular arrays of data - for example, color
data, luminance data, or color and alpha data. The individual values in
a texture array are often called<I> texels</I>. What makes texture mapping
tricky is that a rectangular texture can be mapped to nonrectangular regions,
and this must be done in a reasonable way.
<P>Figure 9-1 illustrates the texture-mapping process. The left side of
the figure represents the entire texture, and the black outline represents
a quadrilateral shape whose corners are mapped to those spots on the texture.
When the quadrilateral is displayed on the screen, it might be distorted
by applying various transformations - rotations, translations, scaling,
and projections. The right side of the figure shows how the texture-mapped
quadrilateral might appear on your screen after these transformations.
(Note that this quadrilateral is concave and might not be rendered correctly
by OpenGL.)
<P><IMG SRC="figures/texfig.gif" ALT="[IMAGE]" NOSAVE >
<P><B>Figure 9-1 : </B>The Texture-Mapping Process
<BR>&nbsp;
<BR>&nbsp;
<P>Notice how the texture is distorted to match the distortion of the quadrilateral.
In this case, it's stretched in the <I>x</I> direction and compressed in
the <I>y</I> direction; there's a bit of rotation and shearing going on
as well. Depending on the texture size, the quadrilateral's distortion,
and the size of the screen image, some of the texels might be mapped to
more than one fragment, and some fragments might be covered by multiple
texels. Since the texture is made up of discrete texels (in this case,
256 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -