A Division of Macmillan USA
201 West 103rd St., Indianapolis, Indiana, 46290
Robert Dunlop
with Dale Shepherd,
Mark Martin, et al
DirectX 7
in
24
Hours
Teach Yourself
00 1634xFM 11/13/99 10:50 AM Page i
Sams Teach Yourself DirectX
7 in 24
Hours
Copyright 2000 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a
retrieval system, or transmitted by any means, electronic, mechanical, photo-
copying, recording, or otherwise, without written permission from the pub-
lisher. No patent liability is assumed with respect to the use of the information
contained herein. Although every precaution has been taken in the preparation
of this book, the publisher and author assume no responsibility for errors or
omissions. Nor is any liability assumed for damages resulting from the use of
the information contained herein.
International Standard Book Number: 0-672-31634-x
Library of Congress Catalog Card Number: 98-83220
Printed in the United States of America
First Printing: December, 1999
01 00 99 4 3 2 1
Trademarks
All terms mentioned in this book that are known to be trademarks or service
marks have been appropriately capitalized. Sams Publishing cannot attest to the
accuracy of this information. Use of a term in this book should not be regarded
as affecting the validity of any trademark or service mark.
DirectX is a registered trademark of Microsoft Corporation.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as
possible, but no warranty or fitness is implied. The information provided is on
an “as is” basis. The authors and the publisher shall have neither liability nor
responsibility to any person or entity with respect to any loss or damages aris-
ing from the information contained in this book or from the use of the CD or
programs accompanying it.
ASSOCIATE PUBLISHER
Bradley Jones
ACQUISITIONS EDITOR
Chris Webb
DEVELOPMENT EDITOR
Matt Purcell
MANAGING EDITOR
Lisa Wilson
PROJECT EDITOR
Tonya Simpson
COPY EDITOR
Rhonda Tinch-Mize
INDEXER
Eric Schroeder
PROOFREADER
Jill Mazurczyk
TECHNICAL EDITOR
Dale Shepherd
TEAM COORDINATOR
Meggo Barthlow
MEDIA DEVELOPER
Dan Scherf
INTERIOR DESIGNER
Gary Adair
COVER DESIGNER
Aren Howell
COPY WRITER
Eric Borgert
PRODUCTION
Brad Lenser
00 1634xFM 11/13/99 10:50 AM Page ii
Contents at a Glance
Introduction 1
PART I Introduction to DirectX 3
1 About DirectX—The Pieces That Make It Happen 5
PART II Getting Started with DirectDraw 15
2 Our First Step—DirectDraw in a Windows Application 17
3 Moving On—Grabbing Control of the System 39
4 Creating the Game Loop 55
5 Make It Move—DirectDraw Animation Techniques 75
PART III Adding Music and Sound 95
6 DirectSound—Adding Ambience and Sound Effects to Your Game 97
7 Applying DirectSound 113
PART IV Welcome to 3D 133
8 DirectMusic—Interactive Music 135
9 Applying DirectMusic 153
10 Introduction to 3D Concepts 181
11 Rendering the 3D Scene 197
PART V Input Devices 209
12 Creating Our First Direct3D Application 211
13 Adding Textures and Z-Buffers to the Scene 247
14 Adding Realism Through Lighting 265
P
ART VI Direct3D Immediate Mode 283
15 Importing 3D Objects and Animations Into the Scene 285
16 Modeling a Complex World—Applying Physics and Object
Hierarchies 309
17 Introducing DirectInput—Getting User Input 333
18 Getting Through to the User—Force Feedback 355
19 3D Sound—From Panning to Doppler Effects 375
00 1634xFM 11/13/99 10:50 AM Page iii
PART VII DirectPlay 399
20 Putting Your Game on the Net—Writing Multiplayer Titles 401
21 Game Central—Creating Lobbies 427
PART VIII The DirectMedia SDK 447
22 Adding Video with DirectShow 449
23 Bring Surfaces to Life with DirectX Transform 465
24 Integrating Media Into Web Pages and Applications with
DirectAnimation 487
PART IX Appendixes 511
A Answers 513
B Prepare Your Application for Distribution with DirectSetup 535
Index 541
00 1634xFM 11/13/99 10:50 AM Page iv
Contents
Introduction 1
P
ART I Introduction to DirectX 3
HOUR 1 About DirectX—The Pieces That Make It Happen 5
What Is DirectX? 5
DirectX Components 6
The DirectX SDK 6
The DirectX Media SDK 7
Preparing to Use DirectX 7
Preparing the Compiler 8
Including the SDK in Your Projects 9
A Brief Introduction to COM 9
Reusable Interfaces and Backward Compatibility 10
The
IUnknown Base Class 11
Querying for Interfaces 11
Reference Counting in COM 12
Summary 13
Q&A 13
Workshop 14
Quiz 14
Exercises 14
P
ART II Getting Started with DirectDraw 15
HOUR 2 Our First Step—DirectDraw in a Windows Application 17
Taking a Look at the Video System 18
The Components of DirectDraw 18
The
IDirectDraw7 Interface 19
DirectDraw Surfaces 21
Keeping Inside the Lines with the DirectDraw Clipper 22
Drawing on a Surface 23
A Function to Load Bitmaps to a DirectDraw Surface 23
Your First DirectDraw Application 26
Setting Up the Project 27
Creating a Windows Framework 28
Initializing DirectDraw and Creating a Clipper 31
Creating the Primary Surface 33
Loading the Image 34
00 1634xFM 11/13/99 10:50 AM Page v
Blitting an Image to the Screen 34
Tying It All Together in the Message Loop 35
Deallocating the Interfaces 36
Summary 37
Q&A 38
Workshop 38
Quiz 38
Exercises 38
H
OUR 3 Moving On—Grabbing Control of the System 39
Full-Screen Graphics 40
Getting the System’s Cooperation 40
Changing the Screen Resolution 41
Page Flipping 42
Creating the Flipping Chain 43
Using Page Flipping 44
Slide Show—A Simple Surface-Flipping Application 45
Setting Up the Application 46
Initializing the Application 47
Cleaning Up 49
Drawing a Slide 49
Handling Slide Navigation 51
Sample Output 52
Summary 53
Q&A 53
Workshop 54
Quiz 54
Exercises 54
H
OUR 4 Creating the Game Loop 55
Conceptual Overview of the Game Loop 55
Writing a Better Message Loop 57
Achieving Smooth Playback 58
Using Timers in the Loop 59
Selecting the Timer 59
Your First Piece of Animation: A Scrolling Background 61
Setting Up the Application 61
Setting Up Initialization 62
Controlling Motion Through Keyboard Input 64
Cleanup on Exit 65
Creating Your Game Loop 66
Rendering a Scrolling Background 69
vi Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page vi
Summary 72
Q&A 73
Workshop 73
Quiz 73
Exercises 73
H
OUR 5 Make It Move—DirectDraw Animation Techniques 75
Transparent Blits 75
The Two Flavors of Color Key 76
Choosing a Key Color 77
Converting the Key Color 77
Setting the Color Key in DirectDraw 79
Making It Look Like 3D 81
Z-Ordering 81
Parallax—Depth Perception of Moving Objects 82
Putting It All Together 83
Loading the Layers 85
Summary 92
Q&A 92
Workshop 93
Quiz 93
Exercises 93
P
ART III Adding Music and Sound 95
HOUR 6 DirectSound—Adding Ambience and Sound Effects to Your Game 97
DirectSound Basics 98
Low-Latency Audio Mixing 99
Hardware Acceleration 99
3D Audio 100
DirectSound and Windows Waves 100
Inside DirectSound 100
The
DirectSound Object 101
The
DirectSoundBuffer Object 104
Static and Streaming Sound Buffers 109
Summary 110
Q&A 110
Workshop 111
Quiz 111
Exercises 111
Contents vii
00 1634xFM 11/13/99 10:50 AM Page vii
HOUR 7 Applying DirectSound 113
DirectSound and Games 114
Working with Waves 115
A High-Level Use for Waves 115
Creating the
CWave Class 117
Using the
CWave Class 123
Playing Sound Effects with DirectSound 124
Summary 131
Q&A 131
Workshop 131
Quiz 131
Exercises 132
P
ART IV Welcome to 3D 133
HOUR 8 DirectMusic—Interactive Music 135
The Features of DirectMusic 136
The Microsoft Synthesizer 137
The Age of Interactive Music 139
Dynamic Creation of Music 139
Composition of Music in the Digital Realm 141
A Quick Primer on Musical Structure 142
Storing Compositions with the MIDI Format 143
Multitrack Music Synthesis 144
DirectMusic Architecture 144
The
IDirectMusicPerformance Interface 144
Interfaces Used with the Performance Object 146
Putting Together the Band 147
Musical Templates 147
Summary 149
Q&A 150
Workshop 150
Quiz 150
Exercises 151
H
OUR 9 Applying DirectMusic 153
Using the DirectMusic Producer to Create a Simple Score 154
Selecting the Instruments 154
Creating a Rhythm 156
Making a Simple Melody 159
Creating Musical Templates 159
Saving the Performance 162
viii Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page viii
Setting Up DirectMusic 162
Initializing the Performance Interface 162
Loading Composition Files 164
Establishing the Instruments 166
DirectMusic Playback 168
Playing Segments 169
Real-Time Changes to Tempo and Structure 169
Adding DirectMusic to Our Game 171
Creating the Interfaces 172
Loading the Performance Components 173
Changing the Music to Reflect the Scene 175
Summary 177
Q&A 177
Workshop 179
Quiz 179
Exercises 180
H
OUR 10 Introduction to 3D Concepts 181
An Overview of the 3D Process 182
Object Definitions 182
The 3D Pipeline 182
Defining Locations in 3D Space 184
The New Origami—Building Objects in 3D 185
Relative Coordinates—Origins and Vectors 186
Matrixes—Making the World Go Round 187
The World Transform 189
The View Transform 194
Summary 195
Q&A 195
Workshop 196
Quiz 196
Exercises 196
H
OUR 11 Rendering the 3D Scene 197
Hierarchy of Direct3D Immediate Mode 197
The IDirect3D7 Interface 198
The
IDirect3DDevice7 Interface 198
The Viewing Frustum 199
Clipping the Frustum to the Field of View 199
Front and Rear Clipping Planes 200
The Projection Matrix, Revisited 200
Defining the Viewport 202
Contents ix
00 1634xFM 11/13/99 10:50 AM Page ix
Hidden Surface Removal 203
Back-Face Culling 204
Z-Buffering 205
Summary 207
Q&A 207
Workshop 207
Quiz 207
Exercises 208
P
ART V Input Devices 209
HOUR 12 Creating Our First Direct3D Application 211
Creating Objects in Direct3D 212
Vertices—A Thousand Points of Light 212
The Three Mesh Formats 213
Triangle Lists 213
Triangle Strips 214
Triangle Fans 214
Drawing a Mesh 215
Indexing a Mesh 216
Drawing an Indexed Primitive 216
Setting Out on Your First Direct3D Adventure 217
Creating a Simple 3D Object 218
Rendering the Object 223
Getting Down to Business 224
Global Interface Pointers 225
Initializing the Application 227
Initializing DirectDraw for Use with Direct3D 228
Initializing Direct3D 230
Setting Up a Viewport 231
Object Creation 232
Putting It in Motion 233
Rendering the Scene 236
Handling User Input 238
The Finishing Touches 240
Running the Application 243
Summary 244
Q&A 244
Workshop 245
Quiz 245
Exercises 245
x Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page x
HOUR 13 Adding Textures and Z-Buffers to the Scene 247
Preparing a Z-Buffered Device 249
Selecting a Z-Buffer 249
Creating and Attaching the Z-Buffer 251
Enabling and Disabling the Z-Buffer 253
Adding Textures 253
Load a Texture 254
Prepare Geometry 259
Set Up the Device and Render 260
Summary 263
Q&A 263
Workshop 264
Quiz 264
Exercise 264
H
OUR 14 Adding Realism Through Lighting 265
Creating a Light 265
Types of Light 266
Point Lights 267
Spotlights 268
Directional Lights 269
Adding Lighting to Our Project 269
Creating the Light 274
Activating the Lighting Pipeline 277
Animating Lights in the Scene 278
Removing the Lights 280
Summary 280
Q&A 281
Workshop 281
Quiz 281
Exercises 282
P
ART VI Direct3D Immediate Mode 283
HOUR 15 Importing 3D Objects and Animations Into the Scene 285
An Overview of 3D Modeling Packages 286
The Direct3D X File Format 286
Vertex Storage 292
Vertex Colors 293
Vertex Normals 294
Texture Maps 295
Frame Hierarchy 296
Animation Paths 297
Contents xi
00 1634xFM 11/13/99 10:50 AM Page xi
Converting 3D Studio Files: The CONV3DS Utility 300
Reading the X File Format 300
Adding Vehicles to Our Application 301
Reading the Model 301
Setting Up the Hierarchy 302
Adding the Object to the Scene 304
Cleaning Up 305
Summary 306
Q&A 306
Workshop 306
Quiz 306
Exercises 307
H
OUR 16 Modeling a Complex World—Applying Physics and Object
Hierarchies 309
Reactions and Effects: Defining Real-World Relationships 310
Motion Dynamics 311
Forward Kinematics 312
Pivot Points and Other Kinematics Features 312
Inverse Kinematics 314
Object Hierarchies 314
Using Matrices to Combine Motions 315
Object Interaction 318
Collision Detection 319
Object Reactions 321
Adding Collision Detection to Our Application 324
Defining Object Bounds 325
Testing for Collisions 328
Animating Reaction Vectors 329
Summary 330
Q&A 330
Workshop 331
Quiz 331
Exercises 331
H
OUR 17 Introducing DirectInput—Getting User Input 333
DirectInput Basics 334
Inside DirectInput 335
The DirectInput Object 336
The DirectInputDevice Object 338
DirectInput Housekeeping 339
Starting Up DirectInput 339
Cleaning Up DirectInput 340
xii Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page xii
Handling Keyboard Input 341
Handling Mouse Input 344
Handling Joystick Input 348
Summary 353
Q&A 353
Workshop 354
Quiz 354
Exercises 354
H
OUR 18 Getting Through to the User—Force Feedback 355
Understanding Force Feedback 356
Force Feedback Lingo 356
Types of Effects 358
Peeking Inside DirectInput 359
Putting Force Feedback to Work 361
Enumerating and Creating Force Feedback Devices 363
Enumerating Force Feedback Effects 365
Creating Force Feedback Effects 367
Playing Force Feedback Effects 370
Altering Force Feedback Effects 371
Force Feedback Effect Recipes 371
Summary 373
Q&A 373
Workshop 374
Quiz 374
Exercises 374
H
OUR 19 3D Sound—From Panning to Doppler Effects 375
Introduction to 3D Sound 376
The Physics of Sound 376
How We Perceive Sound 378
The Architecture of DirectSound3D 380
DirectSound 3D Components 380
DirectSound 3D Buffers 380
DirectSound 3D Listener 386
Adding DirectSound 3D to Your Application 391
Creating the Listener 392
Loading Sounds 394
Creating the 3D Buffer 394
Animating Sound Effects 395
Release Interfaces 396
Summary 397
Q&A 398
Contents xiii
00 1634xFM 11/13/99 10:50 AM Page xiii
Workshop 398
Quiz 398
Exercises 398
P
ART VII DirectPlay 399
HOUR 20 Putting Your Game on the Net—Writing Multiplayer Titles 401
DirectPlay Architecture 402
Creating a DirectPlay Object 408
Choosing a Network Connection 408
Joining a Session 412
Communicating with Players 415
Players and Groups 415
DirectPlay Messages 418
Dealing with Network Latency 419
Deterministic/Non-Deterministic Data 421
Guaranteed Messaging 421
Message Management 422
Summary 423
Q&A 424
Workshop 424
Quiz 425
Exercises 425
H
OUR 21 Game Central—Creating Lobbies 427
Introduction to DirectPlay Lobbies 428
Bringing Players Together Under One Roof 429
The Game Server 431
Making a DirectPlay Application Lobbyable 431
The IDirectPlayLobby Interface 432
Lobby Support for the Game Client 434
Registering the Game as Lobbyable 435
Users, Groups, and Sessions 437
Providing Chat Services 439
Creating a Session 441
Launching a DirectPlay Lobby Application 443
Making the Game Lobbyable 443
Sending and Receiving Lobby Messages 444
Cleanup 445
Summary 445
Q&A 445
Workshop 446
Quiz 446
Exercises 446
xiv Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page xiv
PART VIII The DirectMedia SDK 447
HOUR 22 Adding Video with DirectShow 449
Introducing DirectShow 450
Video Playback Capabilities 450
Internet Streaming Video Applications 451
Graph Filters 454
Stringing Filters Together 455
Sample DirectShow Application 456
Initializing DirectShow 456
Setting Up the Filter 457
Setting Up the File Stream 458
Streaming the Movie 460
Cleanup 461
Summary 462
Q&A 462
Workshop 463
Quiz 463
Exercises 463
H
OUR 23 Bring Surfaces to Life with DirectX Transform 465
The Power of DirectX Transform 466
A Versatile DirectDraw Surface: IDXSurface 467
Creating a
DXSurface 467
Reading Graphics from Various File Formats 468
Automatic Color Conversion 469
Special Effects: DirectX Transforms 470
Creating the Transform Factory 470
Using the Factory to Access Transforms 471
2D Transforms 472
Procedural Surfaces 475
3D Transforms 477
A Sample DirectX Transform Application 480
Create DXSurface Objects 480
Load the Images 481
Create the Transform 482
Animate the Image Transforms 482
Cleanup 483
Summary 484
Q&A 484
Workshop 485
Quiz 485
Exercises 485
Contents xv
00 1634xFM 11/13/99 10:50 AM Page xv
HOUR 24 Integrating Media Into Web Pages and Applications with
DirectAnimation 487
DirectAnimation—One API, Many Uses 488
Scratching the Surface—A Look at the Interfaces 489
DirectAnimation Architecture 490
The DirectAnimation Model 491
A Versatile Programming Environment 492
DirectAnimation Programming in C++ 493
Using Scripts to Use DirectAnimation on the Web 494
Sample DirectAnimation Application in C++ 494
Initializing DirectAnimation 495
Loading 2D Images 500
Creating a 3D Object 501
Adding Some Motion 502
Creating the Camera and Lighting 503
Adding Sound 503
Animating the Scene 504
Cleanup 505
Doing it the DirectDraw Way 505
Sample Web Page Using DirectAnimation 506
Summary 508
Q&A 509
Workshop 509
Quiz 509
Exercises 510
P
ART IX Appendixes 511
APPENDIX A Answers 513
Hour 1, “About DirectX—The Pieces That Make It Happen” 513
Quiz 513
Hour 2, “Our First Step—DirectDraw in a Windows Application” 514
Quiz 514
Hour 3, “Moving On—Grabbing Control of the System” 514
Quiz 514
Hour 4, “Creating the Game Loop” 514
Quiz 514
Hour 5, “Make It Move—DirectDraw Animation Techniques” 515
Quiz 515
Hour 6, “DirectSound—Adding Ambience and Sound Effects to Your Game” 515
Quiz 515
Hour 7, “Applying DirectSound” 516
Quiz 516
xvi Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page xvi
Hour 8, “DirectMusic—Interactive Music” 518
Quiz 518
Hour 9, “Applying DirectMusic” 519
Quiz 519
Hour 10, “Introduction to 3D Concepts” 520
Quiz 520
Hour 11, “Rendering the 3D Scene” 520
Quiz 520
Exercises 521
Hour 12, “Creating Our First Direct3D Application” 521
Quiz 521
Hour 13, “Adding Textures and Z-Buffers to the Scene” 522
Quiz 522
Hour 14, “Adding Realism Through Lighting” 522
Quiz 522
Hour 15, “Importing 3D Objects and Animations Into the Scene” 524
Quiz 524
Hour 16, “Modeling a Complex World—Applying Physics and Object
Hierarchies” 524
Quiz 524
Hour 17, “Introducing DirectInput—Getting User Input” 525
Quiz 525
Hour 18, “Getting Through to the User—Force Feedback” 526
Quiz 526
Hour 19, “3D Sound—From Panning to Doppler Effects” 527
Quiz 527
Hour 20, “Putting Your Game on the Net—Writing Multiplayer Titles” 528
Quiz 528
Hour 21, “Game Central—Creating Lobbies” 530
Quiz 530
Hour 22, “Adding Video with DirectShow” 531
Quiz 531
Hour 23, “Bring Surfaces to Life with DirectX Transform” 531
Quiz 531
Hour 24, “Integrating Media Into Web Pages and Applications with
DirectAnimation” 532
Quiz 532
Exercise 533
A
PPENDIX B Prepare Your Application for Distribution with DirectSetup 535
Index 541
Contents xvii
00 1634xFM 11/13/99 10:50 AM Page xvii
About the Authors
Robert Dunlop is Microsoft’s first and only MVP (Most Valuable Professional) for
DirectX in recognition of his assistance to the game developer community. Robert is a
veteran game developer with more than 10 years of programming experience, and a prin-
cipal of Monarch Interactive, Inc. (www.monarch-interactive.com), a company devoted
to creating new entertainment titles for the PC. Robert works very closely with the
DirectX team at Microsoft and has been on the DirectX Beta Team since 1994.
Mark Martin is a technical analyst for a business service–oriented company, where he
works with a variety of systems and languages specializing in network programming and
distributed computing systems. Additionally, he is a partner in an upstart gaming com-
pany, where he is completing a large multiplayer game using DirectX, playable over the
Internet.
Michael Morrison is a writer, developer, toy inventor, and author of a variety of books,
including Sams Teach Yourself Internet Game Programming with Java in 21 Days and
Windows 95 Game Developer’s Guide. Michael is the creative lead at Gas Hound Games,
a toy company located on the Web at .
Sam Christiansen is a tools and technology programmer at Human Code, an Austin-
based video game company, where he has contributed to several commercial games. In
addition, Sam performs research for the University of Texas Center for Computer
Visualization.
Odin Jensen is a game programmer for Denmark’s largest game developer, where he
works on popular 3D game titles for the Sony Playstation. He provides DirectX wrappers
for beginning game developers at www.nukesoftware.dk.
Josh Martin is a software developer/technical consultant for a custom software firm in
Palatine, Illinois. While his workdays are spent developing business applications, he
spends many hours after work developing multiplayer games for a new gaming company.
Brian Noyes is a software consultant, developer, and technical writer with DomeWorks
Software (). A Microsoft Certified Professional, he has developed
Windows modeling and simulation applications and multimedia utilities for government
and commercial projects.
Kenn Scribner’s multimedia experience began in writing flight simulators for the United
States Air Force using OpenGL. Kenn began to explore alternatives to OpenGL with the
advent of DirectDraw and has continued to use both technologies in his component
development.
xviii Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page xviii
Recognition from the
Publisher
Sams Publishing would like to give a special thanks to Dale Shepherd. His timely and
accurate assistance on this project helped ensure its completion with true coverage of
Microsoft’s newest version of Microsoft’s DirectX—DirectX 7. By helping on this pro-
ject, Dale has created this, the best book available, for the new user of DirectX 7.
Contents xix
00 1634xFM 11/13/99 10:50 AM Page xix
Tell Us What You Think!
As the reader of this book, you are our most important critic and commentator. We value
your opinion and want to know what we’re doing right, what we could do better, what
areas you’d like to see us publish in, and any other words of wisdom you’re willing to
pass our way.
As an Associate Publisher for Sams, I welcome your comments. You can fax, email, or
write me directly to let me know what you did or didn’t like about this book—as well as
what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this
book, and that due to the high volume of mail I receive, I might not be able to reply to
every message.
When you write, please be sure to include this book’s title and author as well as your
name and phone or fax number. I will carefully review your comments and share them
with the author and editors who worked on the book.
Fax: 317-581-4770
Email:
Mail: Associate Publisher
Sams Publishing
201 West 103rd Street
Indianapolis, IN 46290 USA
xx Sams Teach Yourself DirectX 7 in 24 Hours
00 1634xFM 11/13/99 10:50 AM Page xx
Introduction
What an exciting time to be involved in game design and multimedia driven application
development! Computer hardware continues to evolve and increase in speed in shorter
and shorter cycles. And no segment of computer hardware has seen more growth in
recent years than the video card market.
Of course, there’s more to multimedia than video. There’s sound, user input, and
music to produce. The Web has created wonderful opportunities to present video and ani-
mations.
Of course, our jobs as multimedia application developers haven’t gotten easier. With all
this new technology comes complexity and learning. And with this new technology, the
tools available to us to use it effectively also evolve. Microsoft’s DirectX platform has
grown up quite nicely for us.
Many tools and SDKS are in the market to handle the myriad of different aspects
involved in developing multimedia applications. None are as robust and well rounded as
DirectX. With DirectX, you get a very complete set of APIs to use to write next genera-
tion apps and games—rich with multimedia. There’s the Direct3D portion for creating
the (now standard) 3D world for users. DirectMusic and DirectSound cover all your
musical requirements. DirectInput takes care of any user-input requirements. For multi-
player capability, we’ve got the easy-to-use DirectPlay portion.
There are of course many parts to DirectX. And not many books have covered all of
them together, or presented them in an easy-to-use fashion. That’s why you’re reading
this book. For the first time, you’ll be introduced to the whole of DirectX 7 in a practical
way. We’ve covered version 7 from top to bottom. And we’ve presented real-world sam-
ples to give you hands on experience in using DirectX effectively.
You should come away from reading this book with a working knowledge of DirectX 7,
in all of its aspects. And DirectX is a large topic, to be sure. Microsoft has bundled a lot
of functionality in their latest release, and they’ve made it easier than ever for you, as
programmer and designer, to use it.
So sit back, grab a can of pop, and enjoy our fun and fast ride. We’ve got a lot of ground
to cover, and only 24 hours to cover it in. You’ll enjoy every minute of it, as we’ve
enjoyed writing it. You’re well on your way to writing the next blockbuster fully immer-
sive and multiplayer 3D game. And we’re exited to see what will be new in DirectX 8.
01 1634xIntro 11/13/99 11:09 AM Page 1
01 1634xIntro 11/13/99 11:09 AM Page 2
Hour
1 About DirectX—The Pieces That Make It
Happen
PART I
Introduction to DirectX
02 1634xPart I 11/13/99 11:09 AM Page 3
02 1634xPart I 11/13/99 11:09 AM Page 4
HOUR
1
About DirectX—The
Pieces That Make It
Happen
This hour will prepare you for the first steps in learning to program with
DirectX by providing a general overview of DirectX and what you will need
to begin programming in DirectX.
In this hour, you will
●
Learn just what DirectX is
●
Learn the components of DirectX
●
Learn how to use DirectX
●
Be introduced to COM
What Is DirectX?
DirectX is a multimedia development library, created by Microsoft and pro-
vided for royalty-free use in the creation of entertainment titles and other
Windows-based applications.
03 1634xCH01 11/13/99 11:04 AM Page 5