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

📄 chapter05.html

📁 OpenGl红宝书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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 5 - 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>
<HR></PRE>

<H1>
Chapter 5<BR>
Color</H1>
<B>Chapter Objectives</B>
<P>After reading this chapter, you'll be able to do the following:
<UL>Decide between using RGBA or color-index mode for your application
<BR>&nbsp;
<P>Specify desired colors for drawing objects
<BR>&nbsp;
<P>Use smooth shading to draw a single polygon with more than one color</UL>
The goal of almost all OpenGL applications is to draw color pictures in
a window on the screen. The window is a rectangular array of pixels, each
of which contains and displays its own color. Thus, in a sense, the point
of all the calculations performed by an OpenGL implementation - calculations
that take into account OpenGL commands, state information, and values of
parameters - is to determine the final color of every pixel that's to be
drawn in the window. This chapter explains the commands for specifying
colors and how OpenGL interprets them in the following major sections:
<UL>"Color Perception" discusses how the eye perceives color.
<BR>&nbsp;
<P>"Computer Color" describes the relationship between pixels on a computer
monitor and their colors; it also defines the two display modes, RGBA and
color index.
<BR>&nbsp;
<P>"RGBA versus Color-Index Mode" explains how the two display modes use
graphics hardware and how to decide which mode to use.
<BR>&nbsp;
<P>"Specifying a Color and a Shading Model" describes the OpenGL commands
you use to specify the desired color or shading model.</UL>

<PRE>
<HR></PRE>

<H2>
Color Perception</H2>
Physically, light is composed of photons - tiny particles of light, each
traveling along its own path, and each vibrating at its own frequency (or
wavelength, or energy - any one of frequency, wavelength, or energy determines
the others). A photon is completely characterized by its position, direction,
and frequency/wavelength/energy. Photons with wavelengths ranging from
about 390 nanometers (nm) (violet) and 720 nm (red) cover the colors of
the visible spectrum, forming the colors of a rainbow (violet, indigo,
blue, green, yellow, orange, red). However, your eyes perceive lots of
colors that aren't in the rainbow - white, black, brown, and pink, for
example. How does this happen?
<P>What your eye actually sees is a mixture of photons of different frequencies.
Real light sources are characterized by the distribution of photon frequencies
they emit. Ideal white light consists of an equal amount of light of all
frequencies. Laser light is usually very pure, and all photons have almost
identical frequencies (and direction and phase, as well). Light from a
sodium-vapor lamp has more light in the yellow frequency. Light from most
stars in space has a distribution that depends heavily on their temperatures
(black-body radiation). The frequency distribution of light from most sources
in your immediate environment is more complicated.
<P>The human eye perceives color when certain cells in the retina (called
<I>cone cells</I>, or just <I>cones</I>) become excited after being struck
by photons. The three different kinds of cone cells respond best to three
different wavelengths of light: one type of cone cell responds best to
red light, one type to green, and the other to blue. (A person who is color-blind
is usually missing one or more types of cone cells.) When a given mixture
of photons enters the eye, the cone cells in the retina register different
degrees of excitation depending on their types, and if a different mixture
of photons comes in that happens to excite the three types of cone cells
to the same degrees, its color is indistinguishable from that of the first
mixture.
<P>Since each color is recorded by the eye as the levels of excitation
of the cone cells by the incoming photons, the eye can perceive colors
that aren't in the spectrum produced by a prism or rainbow. For example,
if you send a mixture of red and blue photons so that both the red and
blue cones in the retina are excited, your eye sees it as magenta, which
isn't in the spectrum. Other combinations give browns, turquoises, and
mauves, none of which appear in the color spectrum.
<P>A computer-graphics monitor emulates visible colors by lighting pixels
with a combination of red, green, and blue light in proportions that excite
the red-, green-, and blue-sensitive cones in the retina in such a way
that it matches the excitation levels generated by the photon mix it's
trying to emulate. If humans had more types of cone cells, some that were
yellow-sensitive for example, color monitors would probably have a yellow
gun as well, and we'd use RGBY (red, green, blue, yellow) quadruples to
specify colors. And if everyone were color-blind in the same way, this
chapter would be simpler.
<P>To display a particular color, the monitor sends the right amounts of
red, green, and blue light to appropriately stimulate the different types
of cone cells in your eye. A color monitor can send different proportions
of red, green, and blue to each of the pixels, and the eye sees a million
or so pinpoints of light, each with its own color.
<P>This section considers only how the eye perceives combinations of photons
that enter it. The situation for light bouncing off of materials and entering
the eye is even more complex - white light bouncing off a red ball will
appear red, or yellow light shining through blue glass appears almost black,
for example. These effects are discussed in "Real-World and OpenGL Lighting."
<BR>&nbsp;
<PRE>
<HR></PRE>

<H2>
Computer Color</H2>
On a color computer screen, the hardware causes each pixel on the screen
to emit different amounts of red, green, and blue light. These are called
the R, G, and B values. They're often packed together (sometimes with a
fourth value, called alpha, or A), and the packed value is called the RGB
(or RGBA) value. (See "Blending" for an explanation of the alpha values.)
The color information at each pixel can be stored either in RGBA mode,
in which the R, G, B, and possibly A values are kept for each pixel, or
in color-index mode, in which a single number (called the color index)
is stored for each pixel. Each color index indicates an entry in a table
that defines a particular set of R, G, and B values. Such a table is called
a color map.
<P>In color-index mode, you might want to alter the values in the color
map. Since color maps are controlled by the window system, there are no
OpenGL commands to do this. All the examples in this book initialize the
color-display mode at the time the window is opened by using routines from
the auxiliary library, which is described in detail in Appendix E .
<P>Different graphics hardware varies greatly in both the size of the pixel
array and the number of colors that can be displayed at each pixel. On
a given graphics system, every pixel has the same amount of memory for
storing its color, and all the memory for all the pixels is called the
<I>color buffer</I>. The size of a buffer is usually measured in bits,
so an 8-bit buffer could store 8 bits of data (256 possible different colors)
for each pixel. The size of the possible buffers varies from machine to
machine. (See Chapter 10 for more information.)

⌨️ 快捷键说明

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