tutorial - basics
before we start
Hardware requirements: In order to use Direct3D you will need a Pentium class machine
equipped with a Direct3D-compatible video card. Most "3d accelerated" video cards
being produced these days support Direct3D. If you're not sure if
your card supports Direct3D, check with your manufacturer.
Software requirements: In addition
to the hardware, you will need to be running a Microsoft Operating System, such
as Windows 95, 98, Windows NT 4.0, or Windows 2000 with the latest DirectX drivers
installed (Get DirectX drivers from
You will also need a development environment, such as Microsoft
Visual Studio. This tutorial assumes you have Visual C++.
Tip: To check to see if your DirectX system is configured properly,
use the DXDiag utility. Go to a command prompt and type dxdiag.
download and install the directx sdk
Once you have met the hardware and software requirements you are ready to get started.
Go to Microsoft's website and download the DirectX SDK (Software Development Kit).
The SDK is available at the Microsoft Developer Network DirectX
The SDK requires approximately 250mb of free space for a full installation and gives
you all of the libraries, header files, example programs, and documentation you'll
need to write a Direct3D application.
When the download is complete, install the SDK. The default installation directory
is "c:\mssdk", but I like to install things like this under "c:\src\", so I choose
"c:\src\directx" as my install directory. It really doesn't matter what you choose,
just keep it simple and easy to get to.
building your build environment
This section should actually be called "install part 2", because it contains necessary
steps you'll need to take to get your Direct3D build environment going.
Nov 15 2000: The DirectX 8.0 installer will perform these steps for you
automatically if you to tell it to do so. (DirectX 7.0a does not).
Direct3D programs require a few extra libraries and header files than regular Windows
programs, and getting your compiler to recognize this fact can sometimes be tricky.
To get a feel for what it takes to get a Direct3D to compile, let's try compiling
one of the sample programs that come with the SDK. This will also give you an opprotunity
to familarize yourself with the Direct3D SDK layout and your build environment,
if you haven't done so already.
At this point the files for the Dolphin project should be visible in the Workspace browser. Go
ahead and try to build the project (select "Rebuild All" from the "Build" menu). You should
get lots of errors. (If you don't see any errors, that's great. It means your libraries and
header files are all in the right place).
- Open up Visual C++ and select "Open Workspace..." from the File menu.
- Select "Makefiles (.mak)" from the file type selector.
- Brose to SDK_PATH\Samples\Multimedia\D3DIM\src\Dolphin and open up "dolphin.mak", (where
SDK_PATH is the place where you installed the DirectX SDK).
- Visual C++ will now ask you if you want to create a workspace for this project. Say yes.
Why did you get these errors? On my system I've found that I get these errors when one of two things
happen: Either the header files that Visual C++ is using are too old for the SDK, or it couldn't
find the header files at all. To fix the build errors you received you're going to need to
copy the latest header files from the SDK into your build tree.
Now you have the latest up-to-date header files installed. Try building your Dolphin project
again ("Rebuild All" from the "Build" menu).
- Go to "My Computer" and browse to SDK_PATH\Include
- Open up another window and browse to MVS_PATH\VC98\Include, (where MVS_PATH is the place
where you installed Microsoft Visual Studio).
- Copy (don't move-- copy) all of the files in the SDK Include directory into your MVS Include
directory. Notice that most of the files you're repacing are signifcantly smaller than the
new ones from the SDK!
What?!? You still got an error? You'll probably get another error that says something like
"LINK : fatal error LNK1104: cannot open file ...." This is because Visual C++ still doesn't
have the right library files to compile this program. We're going to do something similar
to what we did with the header files to fix this last problem:
Now try building the Dolphin program again. This time, you shouldn't get any errors.
Your build environment is ready to go! (If you want to see the dolphin demo in
action, choose "Execute dolphin.exe" from the "Build" menu and it will run the code
you just compiled). Now you can open up any of the sample programs that come with the
SDK and they should compile without any problems.
- Go to "My Computer" and browse to SDK_PATH\Lib
- Open up another window and browse to MVS_PATH\VC98\Lib
- Copy (don't move-- copy) all of the files in the SDK Lib directory into your MVS Lib
directory *except* the "Borland" directory. (You don't need the Borland compiler
direct3d immediate mode and retained mode
Before we get too deep into Direct3D programming, you should be aware that
Direct3D has two drawing modes: Immediate mode (D3DDIM) and Retained Mode (D3DDRM).
Immediate mode provides low-level, device independant access to 3D drawing routines
in an accelerated manner. Retained mode is designed as a "high level" API for rapid
development of 3D animations or simple rendering. Immediate mode is designed to
be fast-- just the bare essentials you need to get bits up onto the screen, and is
what gaming and graphics developers use to program fast 3D accelerated graphics. This
tutorial will cover using immediate mode.
If you want to just throw a simple 3D animation into your Windows program, you might
want to look into retained mode programming at Microsoft's website. As of August 2000
however, Direct3D retained mode is no longer a part of DirectX Foundation. Although
it may not be supported in the future, it is a very quick and dirty way to embed 3D
into your program.
Nov 15 2000: DirectX 8.0 no longer includes retained mode support, so
if you want to use it you need to get the old DirectX 7.0a SDK.