Open GL Super Bible

Previous Table of Contents Next


All this power makes for some really cool possibilities—photo-realistic 3D graphics to name just one. When Microsoft ported OpenGL to the Windows platform, that enabled creation of high-end graphics applications for PCs. Today’s Pentium and Pentium Pro P Cs are still no match for modern SGI Workstations. But combine them with 3D-graphics accelerated graphics cards, and you can get the kind of performance possible only a few years ago on $100,000 graphics workstations—at a Wal-Mart Christmas special! In the very near future, typical home machines will be capable of very sophisticated simulations, games, and more. Our children will laugh at the term “virtual reality” in the same way we smile at those old Buck Rogers rocket ships.

PC Display Modes

Microsoft Windows revolutionized the world of PC graphics in two respects. First, it created a mainstream graphical operating environment that was adopted by the business world at large and, soon thereafter, the consumer market. Second, it made PC graphics significantly easier for programmers to do. With Windows, the hardware was “virtualized” by Windows display device drivers. Instead of having to write instructions directly to the video hardware, programmers today can write to a single API, and Windows handles the specifics of talking to the hardware. Typically, Microsoft provides in the Windows base package (usually with vendor assistance) drivers for the more popular graphics cards. Hardware vendors with later hardware and software revisions ship their cards with Windows drivers and often provide updates to these drivers on BBSs or on the Internet.

There was a time when Windows shipped with drivers for the Hercules monochrome cards, and standard CGA, and EGA video adapters. Not anymore. Standard VGA is now considered the bottom of the barrel. New PCs sold today are capable of at least 640 ?480 resolution with 16 colors, and the choices of resolution and color depth go up from there.

Screen Resolution

Screen resolution for today’s PCs can vary from 640 ?480 pixels up to 1280 ?1024 or more. Screen resolution, however, is not usually a prime limiting factor in writing graphics applications. The lower resolution of 640 ?480 is considered adequate for most graphics display tasks. More important is the size of the window, and this is taken into account easily with clipping volume and viewport settings (see Chapter 3). By scaling the size of the drawing to the size of the window, you can easily account for the various resolutions and window size combinations that can occur. Well-written graphics applications will display the same approximate image regardless of screen resolution. The user should automatically be able to see more and sharper details as the resolution increases.

Color Depth

If an increase in screen resolution or in the number of available drawing pixels in turn increases the detail and sharpness of the image, so too should an increase in available colors improve the clarity of the resulting image. An image displayed on a computer that can display millions of colors should look remarkably better than the same image displayed with only 16 colors. In programming, there are really only three color depths that you need to worry about: 4-bit, 8-bit, and 24-bit.

4-Bit Color

On the low end, your program may be run in a video mode that only supports 16 colors—called 4-bit mode because there are 4 bits devoted to color information for each pixel. These 4 bits represent a value from 0 to 15 that provides an index into a set of 16 predefined colors. With only 16 colors at your disposal, , there is little you can do to improve the clarity and sharpness of your image. It is generally accepted that most serious graphics applications can ignore the 16-color mode.

8-Bit Color

The 8-bit mode supports up to 256 colors on the screen. This is a substantial improvement, and when combined with dithering (explained later in this chapter) can produce satisfactory results for many applications. There are 8 bits devoted to each pixel, which are used to hold a value from 0 to 255 that references an index into a color table called the palette. The colors in this color table can be selected from over 16 million possible colors. If you need 256 shades of red, the hardware will support it.

Each color in the palette is selected by specifying 8 bits each for separate intensities of red, green, and blue, which means the intensity of each component can range from 0 to 255. This effectively yields a choice of over 16 million different colors for the palette. By selecting these colors carefully, near-photographic quality can be achieved on the PC screen.

24-Bit Color

The best quality image production available today on PCs is 24-bit color mode. In this mode, a full 24 bits are devoted to each pixel to hold eight bits of color data for each of the red, green, and blue color components (8 + 8 + 8 = 24). You have the capability to put any of over 16 million possible colors in every pixel on the screen. The most obvious drawback to this mode is the amount of memory required for high-resolution screens (over 2MB for a 1024 ?768 screen). Also indirectly, it is much slower to move larger chunks of memory around when doing animation, or just drawing on the screen. Fortunately, today’s accelerated graphics adapters are optimized for these types of operations.


Previous Table of Contents Next