|
|
|
I had to wait until the beta release of NT 3.5 before I got my first personal taste of OpenGL. Those first OpenGL-based screensavers only scratched the surface of what was possible with this graphics API. Like many other people, I struggled through the Microsoft help files and bought a copy of the OpenGL Programming Guide (now called simply "The Red Book" by most). The Red Book was not a primer, however, and it assumed a lot of knowledge that I just didn’t have. Now for that confession I promised. How did I learn OpenGL? I learned it by writing a book about it. That’s right, the first edition of the OpenGL SuperBible was me learning how to do 3D graphics myself…with a deadline! Somehow I pulled it off, and in 1996 the first edition of the book you are holding was born. Teaching myself OpenGL from scratch enabled me somehow to better explain the API to others in a manner that a lot of people seemed to like. The whole project was nearly canceled when Waite Group Press was acquired by another publisher halfway through the publishing process. Mitchell Waite stuck to his guns and insisted that OpenGL was going to be "the next big thing" in computer graphics. Vindication arrived when an emergency reprint was required because the first run of the book sold out before ever making it to the warehouse. That was a long time ago, and in what seems like a galaxy far, far away… Only three years later 3D accelerated graphics were a staple for even the most stripped down PCs. The "API Wars," a political battle between Microsoft and SGI, had come and gone; OpenGL was firmly established in the PC world; and 3D hardware acceleration was as common as CD-ROMs and sound cards. I had even managed to turn my career more toward an OpenGL orientation and had the privilege of contributing in some small ways to the OpenGL specification for version 1.2 while working at Lockheed Martin/Real 3D. The second edition of this book, released at the end of 1999, was significantly expanded and corrected. We even made some modest initial attempts to ensure all the sample programs were more friendly in non-Windows platforms by using the GLUT framework. Now, nearly five years later (eight since the first edition!), we bring you yet again another edition, the third, of this book. OpenGL is now without question the premier cross platform real-time 3D graphics API. Excellent OpenGL stability and performance are available on even the most stripped-down bargain PC today. OpenGL is also the standard for UNIX and Linux operating systems, and Apple has made OpenGL a core fundamental technology for the new MacOS X operating system. OpenGL is even making inroads via a new specification, OpenGL ES, into embedded and mobile spaces. Who would have thought five years ago that we would see Quake running on a cell phone? It is exciting that, today, even laptops have 3D acceleration, and OpenGL is truly everywhere and on every mainstream computing platform. Even more exciting, however, is the continuing evolution of computer graphics hardware. Today, most graphics hardware is programmable, and OpenGL even has its own shading language, which can produce stunningly realistic graphics that were undreamed of on commodity hardware back in the last century. (I just had to squeeze that in someplace!) With this third edition, I am pleased that we have added Benjamin Lipchak as a coauthor. Benj is primarily responsible for the chapters that deal with OpenGL shader programs, and coming from the ARB groups responsible for this aspect of OpenGL, he is one of the most qualified authors on this topic in the world. We have also fully left behind the "Microsoft Specific" characteristics of the first edition and have embraced a more multiplatform approach. All the programming examples in this book have been tested on Windows, MacOS X, and at least one version of Linux. There is even one chapter apiece on these operating systems, with information about using OpenGL with native applications. What’s in This Book In these chapters, you will learn the fundamentals of real-time 3D graphics programming with OpenGL. You’ll learn how to construct a program that uses OpenGL, how to set up your 3D-rendering environment, and how to create basic objects and light and shade them. Then we’ll delve deeper into using OpenGL and some of its advanced features and different special effects. These chapters are a good way to introduce yourself to 3D graphics programming with OpenGL and provide the conceptual foundation on which the more advanced capabilities later in the book are based. In the second part, three chapters provide specific information about using OpenGL on the three mainstream operating system families: Windows, MacOS X, and Linux/UNIX. Finally, the third part contains the newest features not just of OpenGL, but of 3D graphics hardware in general today. The OpenGL Shading Language, in particular, is the principal feature of OpenGL 2.0, and it represents the biggest advance in computer graphics in many years. Part I: Classic OpenGL Chapter 2—Using OpenGL Chapter 3—Drawing in Space:
Geometric Primitives and Buffers Chapter 4—Geometric
Transformations: The Pipeline Chapter 5—Color, Materials, and
Lighting: The Basics Chapter 6—More on Colors and
Materials Chapter 7—Imaging with OpenGL Chapter 8—Texture Mapping: The
Basics Chapter 9—Texture Mapping:
Beyond the Basics Chapter 10—Curves and Surfaces Chapter 11—It’s All About the
Pipeline: Faster Geometry Throughput Chapter 12—Interactive Graphics Part II: OpenGL Everywhere Chapter 14—OpenGL on the MacOS
X Chapter 15—GLX: OpenGL on Linux Part III: OpenGL: The Next
Generation Chapter 17—Occlusion Queries:
Why Do More Work Than You Need To? Chapter 18—Depth, Textures, and
Shadows Chapter 19—Programmable
Pipeline: This Isn’t Your Father’s OpenGL Chapter 20—Low-Level Shading:
Coding to the Metal Chapter 21—High-Level Shading:
The Real Slim Shader Chapter 22—Vertex Shading:
Do-It-Yourself Transform, Lighting, and Texgen Chapter 23—Fragment Shading:
Empower Your Pixel Processing Conventions Used in This Book The following typographic conventions are used in this book: • Code lines, commands, statements, variables, and any text you type or see onscreen appear in a computer typeface. • Placeholders in syntax descriptions appear in an italic computer typeface. Replace the placeholder with the actual filename, parameter, or whatever element it represents. • Italics highlight technical terms when they first appear in the text and are being defined. About the Companion CD The CD that comes with the OpenGL SuperBible is packed with sample programs, toolkits, source code, and documentation—everything but the kitchen sink! We dig up stuff to put on this CD all the way until press time, so check out the readme.txt file in the root of the CD for a complete list of all the goodies we include. The CD contains some basic organization. Off the root directory, you’ll find \Examples—Beneath this directory, you’ll find a directory for each chapter in the book that has programming examples. Each sample has a real name (as opposed to sample 5.2c), so you can browse the CD with ease and run anything that looks interesting when you first get the book. \Tools—A collection of third-party tools and libraries appears here. Each has its own subdirectory and documentation from the original vendor. Sample programs throughout the book use some of these tools (GLUT in particular). \Demos—This directory contains a collection of OpenGL demo programs. These programs all showcase the rendering capabilities of OpenGL. Some are free; some are commercial demos. For support issues with the CD, please contact Sams Publishing (www.samspublishing.com). Other OpenGL questions, more samples and tutorials, and, of course, the inevitable list of errata are posted on the book’s Web site at http://www.starstonesoftware.com/OpenGL Building the Sample Programs All the sample programs in this book are written in C. They should be easy to move to C++ for those so inclined, but C usually provides a larger audience for a book such as this, and is readily understood by anyone who might prefer C++. Most programs also use the glTools library, which is simply a collection of OpenGL-friendly utility functions written by the authors. The glTools header file (gltools.h) and source .c files are listed in the \common directory beneath the \Examples directories on the CD. Beneath \Examples, you will find a directory for each OS platform supported. Windows project files are written in Visual C++ 6.0. The reason is that many have chosen not to upgrade to the new .NET-biased version of the tools, and those who have (myself included on many projects) can easily import the projects. MacOS X sample project files were made with XCode version 1.1. Anyone still using Project Builder should upgrade…it’s free, and it will add years to your life. All Mac samples were tested on OS X version 10.3.3. At the time of printing, Apple had not released drivers that support the OpenGL shading language. Latent Mac bugs could show up when it does. Check the Web site referenced in the preceding section for any necessary updates. Linux make files are also provided. There are 10,392,444,224,229,349,244,281,999.4 different ways to configure a Linux environment. Well, maybe not quite that many. Without meaning to sound too harsh, you are pretty much on your own. Because XCode uses a similar gnu compiler that many Linux environments use, you shouldn’t have too many problems. I expect some additional notes and tutorials will show up on the book’s Web site over time. Dare to Dream in 3D! This was possibly the worst advice I have ever received in the history of bad advice. A few years ago, I forgot about being a "respectable" database/enterprise/yada-yada-yada developer. Now I write cool graphics programs, teach graphics programming, own my own software company, and generally have more fun with my career than should probably be allowed by law! I hope I can give you some better advice today. Whether you want to write games, create military simulations, develop scientific visualizations, or visualize large corporate databases, OpenGL is the perfect API. It will meet you where you are as a beginner, and it will empower you when you become your own 3D guru. And yes, my friend, you can make a living making pretty pictures with your computer! —Richard S. Wright, Jr.
|