Chapter 1. Why 3D? Why OpenGL?

 

I mean, if we’re promising to make graphics on the PC better than on a Silicon Graphics workstation, we sure as heck are going to make them better than on a $200 game device.

 
 --Bill Gates

OpenGL is rapidly becoming the industry standard for high-quality 3D graphics applications. It’s available on a variety of hardware platforms and operating systems, including Microsoft’s Windows 95 and Windows NT, IBM’s OS/2, DEC’s AXP and OpenVMS, and X Windows. OpenGL was written with the express intention of becoming a thin software interface to underlying graphics hardware—an arrangement of proven success in the graphics workstation market and now being popularized by its introduction into the personal computer market. With the introduction of OpenGL for Windows 95 and Windows NT the most popular operating systems in the world now have the same high-quality 3D graphics capabilities that were used to produce such excellent 3D renderings as found in the movies Jurassic Park, Toy Story, and Twister, and many of the models regularly seen in the TV series Babylon 5 and Space: Above and Beyond. Not only a fun technology, high-performance 3D graphics are regarded as an important one as well. PC Magazine recognized this when it awarded its 1994 Technical Excellence Award for operating systems to Windows NT Workstation version 3.5. As part of the award citation, PC Magazine asserted: “By implementing OpenGL on NT, Microsoft brought workstation-class graphics to the PC, and—finally—genuine 3D graphics to Windows.”

Good 3D capabilities are becoming an increasingly important part of many fields, including CAD/CAM (computer-aided design/computer-aided modeling), architectural design, product design, financial analysis, computer animation and simulation, multimedia applications, World Wide Web applications using VRML (Virtual Reality Modeling Language), statistical and scientific visualization, medical imaging, publishing, and game design and implementation. With OpenGL on Windows this capability has moved from the realm of the workstation into the much larger domain of the PC.

What’s So Important about 3D?

We are already seeing the effect of this transition on the hardware companies as they all scramble to take advantage of the standardization of a well-defined API (application program interface). By mid-1996 a wave of new products will be taking advantage of this 3D capability, producing an explosion of products in fierce competition. Silicon Graphics Incorporated (SGI) in particular is heading off in a new direction, away from simply dominating the graphics workstation market and instead targeting the consumer personal computer market. If that sounds strange, take a moment to think about it. Would you rather be selling $30,000 machines to an audience of around 250,000 customers or adding an additional business of selling software targeted at 200 million customers, especially if they might be repeat customers?

SGI is not alone in targeting game customers. Microsoft is not above entering the “lowly” game market as evidenced by its huge introduction of Windows 95. After all, it was really just an upgrade to an operating system, not anything startlingly new. Yet the huge furor when it was introduced was caused in no small part by the enormous advertising effort expended by Microsoft in an effort to get people to upgrade—to a new operating system with new capabilities. One of these capabilities is an excellent redesign and enhancement of the video interface, in addition to new input, sound, and networking libraries in the form of the Game Software Development Kit (SDK). Microsoft is betting that it can make a PC the ultimate, generic game platform (which just might steal most of those new customers that SGI is looking at, plus a sizeable chunk of the home game-console market!). What could be better than selling them all new $50 copies of your new operating system? Will Microsoft pull it off? I think so. They have the resources and the talent, and they don’t get scared by a high entry fee. When asked if Microsoft will be in this market for the long run, Bill Gates stated: “Well, we’ve never been capital-constrained.”

But don’t get the idea that everyone is interested strictly in games. In fact, people are just looking at prior history. CD-ROMs were not that commonplace until a few killer games requiring CD-ROMs came on the market. Within three years just about every PC sold from that point on came with a CD player. Since CDs are much cheaper to sell software on than if the software were on multiple floppies, most large programs come on CD, and it’s been a much better deal all around. Customers suddenly get a few hundred megabytes of stuff instead of 15 or 20, and a whole new industry has grown up around the creation and use of CD-ROMs. A few of the more astute players in the computer business, mostly SGI and Microsoft, noticed this cause and effect and set out to build the next incremental wave of improvement: better graphics. But how could they get it started?

Well, just as games launched CD-ROMs into respectability, games can also launch better 2D and 3D graphics. Microsoft in particular is spending huge amounts of cash and hiring some of the best talent in the industry to bolster its standing in the video and graphics arena. The real need is to get the equipment capable of handling 3D graphics into the hands of consumers, and what better proven method than that provided by the CD-ROM model, especially when the industry has agreed to steer it in that direction!

With the release of DirectX, Microsoft’s game interface, and the release of OpenGL, the high-quality 3D API, the PC platform is being transitioned into the equivalent of a personal workstation for less than $5000. In fact, since Windows 95 and NT are 32-bit platforms and not entirely different from X Windows, most workstation software vendors will probably come out with PC versions in the near future, driven simply by market size. When I was at a C++ conference in 1989 and talking to another engineer, who happened to develop workstation software, he looked down his nose with obvious disdain when I told him I wrote PC software. With a wave of his hand he dismissed its importance and said, “Oh, how much of that stuff can you sell?” When I mentioned that in the last year we’d sold almost $500 million, his jaw dropped and he was literally speechless, since a workstation software company with sales of $10 million was considered to be doing rather well. Herein lies the effect of having a large customer base!

In change lies opportunity. The September 4, 1995, issue of Business Week had a cover story on 3D graphics. That such a staid business publication should devote its cover story to a particular type of computer application is amazing, but perhaps it’s a good indication that more than a few people are aware of what the next couple of years will bring. In fact, a quote from the article brings home the point: “In these early days of the 3D boom, demand is growing at such a rapid pace that plenty of suppliers should be able to make a buck off the third dimension.”

Although that quote is directed mostly at the video manufacturers, it’s just as true for anyone writing the software to take advantage of this new capability. If you’ve watched the industry for any length of time, you know that when a technology gets hot, developers who already are established are worth their weight in gold. Of course, we’re at a junction. There might be OpenGL programmers, and there might be Windows programmers, but very very few are both. Opportunity beckons.

Learning OpenGL on Windows

The introduction of OpenGL onto a Windows platform entails its own edification of a new legion of graphics programmers, since the blending of a workstation-based graphics API with a common PC operating system ushers in an entirely new realm of programming on the PC. That’s where this book comes in. If you’re interested in fast rendering of high-quality 3D images on Windows 95 and Windows NT, you’ve come to the right place. This book makes heavy use of Microsoft’s Visual C++ programming platform, the C++ programming language, and the Microsoft Foundation Classes (MFC) as wrappers to the generic Windows API, but it starts off with a generic C application that can be compiled from any 32-bit C compiler that provides access to the OpenGL headers. With some minor work you can run OpenGL programs with compilers from Borland, Symantec, or Watcom. This book will cover the basics of creating an OpenGL program, from the selection of the appropriate pixel format to the arrangement of the device context and rendering contexts. We’ll touch on everything that you’ll need to know about OpenGL on Windows in detail so that you have a good basis to further expand your 3D graphics programming expertise. In the later chapters we’ll cover how to go about enhancing OpenGL programs to get the maximum speed out of them.

From using display lists and texture maps to finding out about OpenGL enhancements that may be residing, hidden, in your video driver: We’ll start programming a real application and take it step by step through enhancements, applying what we’ve learned about increasing OpenGL rendering. We’ll cover how to program OpenGL’s Modelview matrix and explain how to use it to get the effects you want. We’ll start off by programming a simple OpenGL program to demonstrate setting up Windows to run OpenGL. We’ll go into detail about the pixel format specifier and why you should understand what it is and how it’s important for a Windows programmer to know how to program it. We’ll write a few tools so that you can examine the OpenGL implementation on your computer and how that implementation can be different on the same PC.

Along the way we’ll get introduced to some tools that Microsoft provides—but doesn’t really document—for measuring a program’s speed; and no, I’m not talking about the profiler! We’ll learn how to provide rapid animation under Windows without bogging down the user interface. And as we go through each step, we’ll be building up an application that you can experiment with and use. The MFC OpenGL View Class will give you some hands-on experience at designing, creating, programming, and optimizing an OpenGL 3D animation program. You’ll learn how to measure OpenGL calls to see what arrangements perform faster, how to select one video mode over another, and how to precompile primitives into display lists for rapid rendering execution. We’ll also collect some programming tricks that you can use to further enhance the rendering speed.

Summary

OpenGL is an operating system–and hardware platform–independent graphics library designed to be easily portable yet rapidly executable. It brings a standard 3D graphics library with the hardware-enhanced ability to perform lighting, shading, texture mapping, hidden-surface removal, and animation onto the Windows platform for the first time. Some of the main features of OpenGL include the following:

  • Texture mapping: the ability to apply an image to a graphics surface. This technique is used to rapidly generate realistic images without having to specify an excessive amount of detail. For example, you could create a wooden floor by painting the floor’s rectangular surface with a woodgrain texture.

  • z-buffering: the ability to calculate the distance from the viewer’s location. This makes it easy for the program to automatically remove surfaces or parts of surfaces that are hidden from view.

  • Double buffering: support for smooth animation using double buffering. A smooth animation sequence is achieved by drawing into the back buffer while displaying the front buffer and then swapping the buffers when you’re ready to display the next animation sequence.

  • Lighting effects: the ability to calculate the effects on the lightness of a surface’s color when different lighting models are applied to the surface from one or more light sources.

  • Smooth shading: the ability to calculate the shading effects that occur when light hits a surface at an angle and results in subtle color differences across the surface. This effect is important for making a model look “realistic.”

  • Material properties: the ability to specify the material properties of a surface. These properties modify the lighting effects on the surface by specifying such things as the dullness or shininess of the surface.

  • Alpha blending: the ability to specify an alpha, or “opacity,” value in addition to the regular RGB (red/green/blue) values. The alpha component is used to specify opacity, allowing the full range, from completely transparent to totally opaque. When used in combination with the z-buffer, alpha blending gives the effect of being able to see “through” objects.

  • Transformation matrices: the ability to change the location, size, and perspective of an object in 3D coordinate space. This gives you the freedom to change an object’s size and location just by modifying the elements of the matrix.

OpenGL is an interface that’s designed, maintained, and enhanced by the OpenGL Architecture Review Board (ARB)—a collection of interested software and hardware companies, including Digital Equipment Corporation, Evans and Sutherland, IBM, Intel, Intergraph, Microsoft, and Silicon Graphics. These companies have a vested interest in seeing that OpenGL becomes the standard for high-quality 3D graphics. The introduction of OpenGL as a native part of the operating system on the Windows NT 3.5 platform in mid-1994 and its ability to run directly on the initial release of Windows 95 marks the onset of high-performance 3D graphics capabilities on a PC. The pressure to provide a 3D library with texture mapping and lighting capabilities has been building for a long time, and now it’s here! Already hardware companies are starting to provide video boards that have built-in OpenGL routines—hardware that can easily speed up the average OpenGL program twenty to fifty times. This pushes the rendering speeds for simple models, say, less than 100,000 polygons, to video frame rates, the rate needed to provide the true illusion of motion. Due to the marriage of a slim API linked with underlying accelerated graphics hardware, we are now seeing PC-based 3D applications that were unthinkable just a few years ago.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.35.81