3d Game Programming with C++ Gold Book with CD-ROM

3d Game Programming with C++ Gold Book with CD-ROM



Product Details

ISBN-13: 9781576104002
Publisher: Coriolis Group
Publication date: 11/28/1999
Edition description: Bk&CD
Pages: 799
Product dimensions: 7.28(w) x 9.12(h) x 1.70(d)

Read an Excerpt

Chapter 1: What Are 3D Games?


Today's games increasingly make use of shadows, which Direct3D supports. Game designers usually decide that not all objects should have shadows-only select objects (like characters and moving vehicles, for example), because using shadows for all objects within a 3D world is computationally expensive.

Many objects, because they do not move, can be given textures with predrawn shadows, eliminating the computational cost at the expense of memory. Another technique involves modifying the intensities of the polygon's vertices (similar to Gouraud shading), making those that lie within shadow regions darker and those that do not, lighter. This technique crudely approximates real shadows, but is fast and universally supported by hardware.


Another feature of Direct3D games is support for hardware acceleration. Every hardware device that includes solid DirectX drivers-and most such devices do-is instantly compat, ible with all existing DirectX games. This reduces user headaches and allows you, as a developer, to concentrate on game issues rather than hardware issues.

DirectX allows hardware acceleration for 3D graphics, 2D graphics, sound output, and input devices (some of which have miniature computers built inside to reduce strain on the CPU). As far as this book is concerned, the most important of these accelerated areas is 3D graphics.

3D Hardware Acceleration

Years ago, not even the fastest computer could produce a quality three-dimensional environment running at playable speeds by using an elegant C++ solution. Programmers who wanted to write 3D games were thus forced to use low,level andpainstakingly optimized assembly language. Even the fastest assembly code was not fast enough; however, programmers had to go beyond this by using clever tricks that often restricted features. The computer game Doom, for example, didn't allow arbitrary polygonal shapes or even slanted walls to inhabit its worlds. It also restricted players to strictly two-dimensional maps-no two floors could exist at any one location. Players weren't even free to look in arbitrary directions (the looking up and down that did exist was noticeably faked)

Descent, the popular 3D space action game, went beyond Doom by allowing a truly three, dimensional world, but even it had its limitations: It ran in low resolution, with some constraints on the manner in which worlds were formed, and the texture mapping quality was crude.

Manufacturers of graphics cards were aware of the PCs lack of built-in 3D hardware and seized the opportunity to incorporate 3D hardware on their products. Though 3D graphics cards were standard equipment in the high-end workstations used by computer artists, such cards were new to the PC world. As the first few cards were released, gamers were disappointed when they discovered a Pentium could easily outperform the best of the pricey accelerators (with some degradation in image quality). Their outlook changed, however, around the time 3DFX released the Voodoo, an amazing chip capable of outperforming in both speed and quality the fastest Pentium. Other companies, such as nVidia, also released high-performance chips. Computer companies and gamers rushed to buy these secondgeneration accelerators, inducing other companies to make 3D cards. Thus was born a competitive, performance-driven market that continues today.

The Features Of Hardware

Today's average 3D card includes the following features, all of which can be relied on in Direct3D games:

  • 16MB or more of video memory
  • Texture mapping
  • Transparency, shading, and bump mapping
  • Geometry acceleration

Video Memory

Graphics cards use video memory to store geometric and graphical information. Direct3D, in particular, uses video memory for the following purposes:

  • For the video mode they run in-Games usually run in full-screen mode, meaning the game chooses and sets its resolution and color depth, rather than using the one that Windows is using. Higher resolutions and color depths require more memory.
  • For storing the geometry of their objects-Before cards can perform mathematical operations on geometry (such as polygons), the geometric information must be moved to video memory.
  • For the depth buffer-The depth buffer is a piece of memory that stores one depth value for each pixel. It is used to allow close objects to obscure objects behind them, and it is implemented in most hardware. Depth buffers typically consume as much or more memory than that used by the video mode.
  • For graphical information-Textures, bump maps, light maps, and other kinds of graphical information can be stored in video memory.
  • For alpha information-Transparency data, such as stencils and alpha channels, can be stored in video memory.

Texture Mapping

Graphics cards can texture polygons in many different ways. The most common methods are referred to as nearest point, bilinear filtering, and trilinear filtering (bilinear and trilinear will be discussed later in this book). Each of these methods first calculates which pixel in the texture map should be mapped onto a given pixel on the polygon. Because this point is not whole (that is, it is a point containing fractions), the hardware must choose which pixel should be used. The nearest-point method rounds the fractional point to the nearest point. The other methods use parts of several surrounding pixels. Thus, the nearest-point method produces the lowest quality output, whereas the others produce much higher-quality polygons. The nearest-point method is no longer considered an acceptable texture-mapping method, because all new graphics cards support at bilinear and trilinear filtering. Many graphics cards also support hardware texture compression and decompression, allowing many more textures to fit into video memory.

Geometry Acceleration

Direct3D allows graphics cards to handle more than just graphical output. They can also accelerate the processing of geometry, which must occur before such data can be displayed. Few graphics cards fully accelerate geometry processing (but CPU extensions, such as AMDs 3DNow!, help with this); most, however, do at least triangle set up, which is the mathematical set up that must be performed immediately before a triangle can be displayed. (All polygons are broken down into triangles before being displayed.)

Transparency, Shading, And Bump Mapping

All of today's 3D graphics cards support alpha,channel transparency. Many also support stenciling, the faster method of transparency mentioned earlier. As a programmer, these methods allow you to use pixel-precise transparency in your games.

Another universal feature of graphics cards is their support for shading. They can display polygons shaded by-lights, as well as perform Gouraud shading and fog effects.

Lastly, most graphics cards support hardware bump mapping, allowing an unprecedented level of realism for polygons.


The first step in becoming a three-dimensional game programmer is to understand what elements contribute to the graphics of three-dimensional games. For Windows programmers, those elements are usually the features supplied by Microsofts DirectX, a high-performance COM SDK aimed specifically at the game-developer community. DirectX gives developers direct control over graphics accelerators, input devices, sound cards, and more.

Credit goes to the manufacturers of graphics accelerators for the radical new advances in the quality and performance of three-dimensional games. These graphics accelerators natively support a growing list of 3D features, enabling developers to produce games that are richly detailed and run at high speeds.

The next chapter takes you through the architecture of 3D games, covering some of the mathematics you will use when writing for Direct3D...

Table of Contents

Part I: The Foundations of 3D Programming
Part II: Programming With DirectX
Part III: DirectX Reference
Part IV: Trig, Points, and Vectors

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews

3d Game Programming with C++ Gold Book with CD-ROM 2.8 out of 5 based on 0 ratings. 5 reviews.
Guest More than 1 year ago
This book would've been great if I had needed some sleep. The problem with this book is that it said something in 5 pages that could've been said in 1. I also believe that this book was aimed more at complete beginners, such as 1st graders. For a 500 page book I thought it gave a pretty lousy idea of how to program with C++. I was quit disappointed.
Guest More than 1 year ago
This book explains a lot of stuff with great organization. The problem with any book from de Goes is that he doesn't know how to explain any of the code. He will give you one little paragraph for two pages of code. He probably just found code off the internet, and threw it into the book. He also caries his tradition of putting in unworking code just like in the Cutting Edge book. I would recommend this book to readers interrested in fiction and delusions but not interrested programmers.
Guest More than 1 year ago
With the 500 pages of basic MSDN information I was pretty upset with this book. The author literally flew through the IM section of the book. Don't bother buying this book, or any book that 'claims' to cover D3D IM. Go check out some user boards, web pages, or the MSDN, you'll have a better experience there.
Guest More than 1 year ago
I wanted to follow up on my earlier posting and make a point or two. My initial reaction to the book was based on expectations that I had rather than being an objective critique. I have had time to reflect and reread the material and I must say that there actually is alot of good stuff there. This book is a good reference at the high level. It is not a 'build from the ground up' type of book. It makes assumptions about your level of expertise (it is for intermediate to advanced technologists and says so right on the back cover) that I failed to take into consideration in my last review. Anyway, while not perfect, it does provide a wealth of useful mathematics, optimization and even good overall coverage of DX. It may not hold your hand every step of the way, but the truth is, there really are no shortcuts when it comes to building these types of games. It is difficult and as programmers, we must be prepared for the challenge. I recommend the book to anyone who has the guts to build their own 3d game engine. It gets 5 stars because, while I still wish it had more info, I nevertheless find myself referring back to it over and over again. Great reference for advanced developers!
Guest More than 1 year ago
I posted a review earlier that was based on my initial expetactions of what this book should have been. It was unfair. In fact, using this book as a guide, I have been able to actually get a halfway decent 3d game engine together in a relatively short time. Note that I said that I used it as a guide. This book does not hold your hand, but rather helps the programmer to push forward using the material provided. It is an excellent resource. It is for intermediate to advanced programmers (says so right on the back cover) and gives you some excellent suggestions for building and optimizing your 3d world. The DX tutorials are brief yet complete and give you what you need to get going. The mathematics and physics sections are certainly top-notch. When I see how far I have come, thanks to John's material, I am truly amazed. Sure it is difficult and sometimes frustrating to build a 3d game world, but that challenge is what makes it exciting and satisfying when we succeed. This book will help you do it. It won't do the work for you, and for that I am glad. If you are an experienced programmer and want to tackle this complex challenge, this book is the perfect tool to help you get there. Highly recommended.