dedication xvi
introduction xvii
acknowledgements xx
Part I
1 DirectX fundamentals 3
1.1 What is DirectX? 3
1.2 How does Direct3D fit in? 5
1.3 What it can do from a 3D perspective 7
1.4 Performance and device independence 8
1.5 Why Windows is better than DOS 8
1.6 Why Windows needs Direct3D 9
1.7 Hardware versus software 9
1.8 What form does Direct3D take? 10
Immediate Mode 10, Retained Mode 11, Direct3D file format 11
1.9 COM objects 12
The vtable and the first argument in a method call 14, An example of the difference between a C and a C++ method call 14
1.10 What did we learn? 15
1.11 What's next? 15
2 The main window 16
2.1 Introduction 16
The Retained-Mode tutorial format 17
2.2 Creating our application's main screen 18
2.3 How to structure your Direct3D code 19
2.4 The includes and the variables 19
2.5 The forward declarations 21
2.6 The main window 22
The message processing loop 23
2.7 The accelerators 24
2.8 Implementing an error handler 26
2.9 The supporting functions 27
2.10 Defining our window 27
2.11 Creating our window 28
2.12 Message handling 30
2.13 The application window 32
2.14 What did we learn? 32
2.15 What's next? 32
3 The Direct3D code and message processing loop 33
3.1 Introduction 33
3.2 Our new and modified data structures 34
Our TutorInfo structure 35
3.3 Our new D3DRM set-up code 36
3.4 Creating our main Direct3DRM object 36
3.5 Creating our DirectDraw Clipper object 36
3.6 Defining our color model 38
Enumerating our drivers and showing our window 40
3.7 Creating the device and viewport 41
Setting our maximum rendering quality 42, Color depth and other rendering settings 43
3.8 Creating our scene and viewport 46
Viewport 47, Camera 48, The viewing frustum 48, Rebuilding the device 50, Dithering 51, Recreating our device 52
3.9 Obtaining the most capable device 53
Checking if the system supports Direct3D 55, Getting the most capable device 55, Finding the bits per pixel 56
3.10 Rendering of our Direct3D virtual world 58
3.11 The additions to our WindowProc routine 59
Handling mouse events 59, Handling window activation 60
3.12 What did we learn? 61
3.13 What's next? 61
4 Creating the lighting 62
4.1 Introduction 62
4.2 Lighting overview 63
Ambient lighting 63, Point source lighting 65, Parallel point lighting 65, Spotlights 66, Directional lights 68
4.3 The color of light 69
The direction of light 70, The range of light 70, Spotlight features 70
4.4 Frames and how to use them with light objects 70
4.5 Visual object hierarchies 71
4.6 A quick graphics fundamentals overview 71
Object transformations 72, Translation 73, Rotation 73, Scale 74
4.7 Frame transformations 75
4.8 Frame motion 78
4.9 Callback functions 78
4.10 How to put it all together 79
4.11 What did we learn? 82
4.12 What's next? 82
5 Loading an object 83
5.1 Visual object loading overview 83
5.2 Loading a DirectX file format object 84
The Mesh and MeshBuilder objects 84, Setting the color of the object 86, Loading the object 87
5.3 Advanced object loading 89
Loading textures 90, Positioning and scaling an object 91, Loading the animation 92, Loading a frame hierarchy 98
5.4 Our new CreateScene routine 100
5.5 The DirectX file object format--a description 102
The DirectX file format 103, Data 106, Identifier 106, Name 106, UUID 106, Data members 106, Commas and semicolons 106, An example DirectX file 108, An AnimationSet in your file 110
5.6 Using .3ds files and 3D Studio 111
5.7 What does our application look like now? 118
5.8 What did we learn? 119
5.9 What's next? 119
6 Adding keyboard and mouse control 120
6.1 Keyboard input overview 120
6.2 What can we do with keyboard input? 121
6.3 Adding the keyboard event handler to our code 121
Acting upon the key presses 124
6.4 What about mouse input? 127
6.5 Adding the Mouse Handler to our code 128
Implementing mouse selection of visual objects (picking) 128, Implementing movement using the mouse 131
6.6 What does our application look like now? 136
6.7 What did we learn? 136
6.8 What's next? 136
7 Building an object 138
7.1 Creating a Direct3D object 138
The Mesh object 138
7.2 The MeshBuilder object 139
7.3 Using the Mesh and MeshBuilders 141
The createPoints routine 143, Normals 144, Creating our landscape 149
7.4 Putting it all together 151
The additions to our CreateScene routine 152, Our motion callback routine for dynamic surface simplification 155
7.5 Some final additions to our CreateScene routine 160
7.6 What does our application look like now? 161
7.7 What did we learn? 162
7.8 What's next? 163
8 Attaching materials and textures 164
8.1 Direct3D texture and material overview 164
8.2 The Direct3DRMTexture interface 164
Using our DirectDraw surface for textures 165
8.3 The Direct3DRMMaterial interface 167
8.4 Applying textures and materials to our objects 168
Wrapping flags 169, Flat 170, Cylindrical 170, Spherical 171, Chrome 171
8.5 Creating a texture and wrapping an object 172
8.6 Advanced texture types 175
Mipmaps 176, Decals 179, Texture transparency 183
8.7 What did we learn? 184
8.8 What's next? 185
9 Adding joystick control 186
9.1 A quick joystick input overview 186
Handling the joystick input 187, The JOYCAPS structure 189
9.2 Adding joystick input to our world 190
The JOYINFOEX structure 190, Setting up our joystick 194, Handling the joystick movement 195
9.3 What did we learn? 199
9.4 What's next? 199
10 What about collision detection? 200
10.1 What is collision detection? An overview 200
10.2 Using the Mesh object's GetBox method 201
10.3 A new collision detection class! 202
10.4 The collision detection code 203
Our base collision object class 204, Our other collision classes 204, The CameraMove callback function 206, Our overloadable collision member function 208, The prism collision member function 208, The sphere collision member function 209, The cylinder collision member function 210
10.5 What does our application look like now? 211
10.6 What did we learn? 211
10.7 What's next? 212
11 Adding sound 213
11.1 A quick DirectSound overview 213
11.2 What is a wave file? 214
11.3 Adding a wave file 215
11.4 Adding simple DirectSound capabilities to our world 217
11.5 Loading a wave file 219
11.6 Parsing a wave file 222
11.7 Setting up our sound buffers 225
11.8 Playing our sounds 229
11.9 Playing a MIDI file 232
11.10 3D sound 233
11.11 Sound cones 234
11.12 Maximum and minimum distances 235
11.13 Position versus velocity 236
11.14 The actual code 236
11.15 What did we learn? 239
11.16 What's next? 240
12 Some advanced Direct3D features 241
12.1 Advanced Direct3D features 241
12.2 Animations 242
Multiple movement animation sequences 243, Setting up our animation callback structure 244, Scaling and positioning our objects 245, Loading the AnimationSet 246, The code to load and view our AnimationSet 248
12.3 Shadows 250
A CreateScene routine for setting up and viewing our object and its shadow 250
12.4 Fog 256
12.5 What did we learn? 257
12.6 What's next? 257
13 How to make things run even faster 258
13.1 Graphics accelerator overview 258
13.2 What should I look for in an accelerator? 259
13.3 A few hints on making your code run faster 260
13.4 What's next? 261
14 A Terrain Modifier 262
14.1 The program 263
14.2 Manipulating the terrain 265
The routines to create and organize our landscape 269, Our new CreateScene routine 270
14.3 What did we learn? 272
14.4 What's next? 272
15 An example full screen application 273
15.1 Why full screen 273
15.2 DirectDraw with Direct3D 274
15.3 The DirectDraw driver COM interface 275
15.4 Setting the display mode 275
15.5 Creating a primary surface 276
15.6 Creating a DirectDraw surface 277
15.7 Creating a Z-buffer surface 278
Using color keying 279
15.8 Loading a BMP file into a DirectDraw surface and creating a palette 280
15.9 Setting up, updating, and viewing our 3D scene 285
15.10 The WindowProc routine 288
15.11 Animated textures--playing an AVI file on your object! 289
15.12 What did we learn? 289
15.13 What's next? 290
16 Now, after all that, what about Immediate Mode? 291
16.1 What about the other half--Immediate Mode? 291
16.2 Setting up your first Immediate-Mode application 292
Debugging your code 292, The debug files 293, The DirectDraw setup code 295, The main loop 297, The InitApp routine 298, The InitServices routine 299,Initializing DirectDraw 299, Creating our surfaces 302, Clearing the back buffer 304, Swapping buffers 305, Create our color map 306, Setting our palette 307, Sharing palettes 308, Message handling 311
16.3 What did we learn? 311
16.4 What's next? 311
17 Setting up Immediate Mode for 3D 312
17.1 Getting ready for 3D 312
17.2 Choosing your DirectDraw device 313
17.3 Enumerating the display modes 313
17.4 Creating your IDirect3D object 314
17.5 Enumerating the D3D Drivers 314
17.6 Choosing your D3D driver 316
17.7 Setting the cooperative level 316
17.8 Creating your front buffer, back buffers, and clipper 316
17.9 Creating your Z-buffer 319
17.10 Creating the IDirect3DDevice 321
17.11 Creating your IDirect3DViewport and attaching it to your D3DDevice 321
17.12 Drawing to your screen 322
17.13 What did we learn? 324
17.14 What's next? 324
18 Creating and displaying 3D objects in Immediate Mode 325
18.1 How do I make a 3D object? 325
18.2 So, what does an execute buffer look like? 326
Vertex data 326, Process vertices 326, Triangle data 327, OP_EXIT 327
18.3 Creating the execute buffer 327
18.4 Filling the execute buffer 333
The vertex data 334, The state information 335, Vertex handling 337, Drawing our object 337
18.5 Rendering the scene 338
18.6 BeginScene / EndScene 339
18.7 What did we learn? 342
18.8 What's next? 342
19 Some final ideas 343
19.1 Where can we go from here? 343
19.2 DirectX 5--DrawPrimitive 344
The core draw primitives of DrawPrimitive 345, The architecture of DrawPrimitive 346
19.3 Simulation and game applications 347
19.4 Virtual reality 348
19.5 Advertising 349
19.6 Have fun! 349
Part II A Direct3D Retained-Mode reference 351
20 Direct3D Retained Mode overview 353
20.1 The Direct3D Retained-Mode interfaces 353
20.2 The format for the D3D Retained Mode commands 354
Description 354, C++ specification 355, Parameters 355, Returns 355, Include file 355, See also (related objects/messages) 355, Example 355
21 The IDirect3DRM interface 356
22 The IDirect3DRMAnimation interface 385
23 The IDirect3DRMAnimationSet interface 394
24 The IDirect3DRMDevice interface 399
25 The IDirect3DRMFace interface 417
26 The IDirect3DRMFrame interface 433
27 The IDirect3DRMLight interface 483
28 The IDirect3DRMMaterial interface 497
29 The IDirect3DRMMesh interface 503
30 The IDirect3DRMMeshBuilder interface 527
31 The IDirect3DRMObject interface 562
32 The IDirect3DRMPickedArray interface 571
33 The IDirect3DRMShadow interface 576
34 The IDirect3DRMTexture interface 579
35 The IDirect3DRMUserVisual interface 598
36 The IDirect3DRMViewport interface 601
37 The IDirect3DRMWinDevice Interface 630
38 The IDirect3DRMWrap interface 634
39 The Direct3D Retained Mode structures 640
40 The Direct3D Enumerated and other types 647
41 The Direct3D Retained Mode file format templates 665
appendix: CD contents 677
index 691