Game Development Reference
In-Depth Information
on the graphics chip. See, it's not magic! The reason you should be aware of the inner workings,
at least at a high level, is that it allows you to understand the performance characteristics of your
application. When vsync is enabled, you can never go above the refresh rate of your screen,
which might be puzzling if all you're doing is drawing a single pixel.
When we render with non-hardware-accelerated APIs, we don't directly deal with the display
itself. Instead, we draw to one of the UI components in our window. In our case, we deal with
a single UI component that is stretched over the whole window. Our coordinate system will
therefore not stretch over the entire screen, but only our UI component. The UI component
effectively becomes our display, with its own virtual framebuffer. The operating system will then
manage compositing the contents of all the visible windows and ensuring that their contents are
correctly transferred to the regions that they cover in the real framebuffer.
What Is Color?
You will notice that we have conveniently ignored colors so far. We made up a type called color
in Figure 3-21 and pretended all is well. Let's see what color really is.
Physically, color is the reaction of your retina and visual cortex to electromagnetic waves. Such
a wave is characterized by its wavelength and its intensity. We can see waves with a wavelength
between roughly 400 and 700 nanometers (nm). That sub-band of the electromagnetic spectrum
is also known as the visible light spectrum. A rainbow shows all the colors of this visible light
spectrum, going from violet to blue to green to yellow, followed by orange and ending at red.
All a monitor does is emit specific electromagnetic waves for each pixel, which we experience
as the color of each pixel. Different types of displays use different methods to achieve that
goal. A simplified version of this process goes like this: every pixel on the screen is made up of
three different fluorescent particles that will emit light with one of the colors red, green, or blue.
When the display refreshes, each pixel's fluorescent particles will emit light by some means (for
example, in the case of CRT displays, the pixel's particles get hit by a bunch of electrons). For
each particle, the display can control how much light it emits. For example, if a pixel is entirely
red, only the red particle will be hit with electrons at full intensity. If we want colors other than the
three base colors, we can achieve that by mixing the base colors. Mixing is done by varying the
intensity with which each particle emits its color. The electromagnetic waves will overlay each
other on the way to our retina. Our brain interprets this mix as a specific color. A color can thus
be specified by a mix of intensities of the base colors red, green, and blue.
Color Models
What we just discussed is called a color model, specifically the RGB color model. RGB stands
for red, green, and blue, of course. There are many more color models we could use, such as
YUV and CMYK. In most graphics programming APIs, the RGB color model is pretty much the
standard, though, so we'll only discuss that here.
The RGB color model is called an additive color model, due to the fact that the final color
is derived via mixing the additive primary colors red, green, and blue. You've probably
experimented with mixing primary colors in school. Figure 3-22 shows you some examples for
RGB color mixing to refresh your memory a little bit.
 
Search WWH ::




Custom Search