This article is brought to you by Premier Press
publisher of Kevin Hawkins’ and Davide Astle’s OpenGL Game Programming.
DirectX is Microsoft’s attempt at a set of APIs that provide "direct" access to hardware in the Windows operating system environment. Each API controls a set of low-level functions that access the hardware or provide hardware emulation if no hardware exists. These functions include support for 2D and 3D graphics acceleration, control over myriad input devices, functions for mixing and sampling sound and music output, control over networking and multiplayer gaming, and control over various multimedia streaming formats. The component APIs that handle these functions are the following:
Microsoft’s philosophy with DirectX is to make a fast, device-independent,
and feature-rich multimedia solution for the Windows operating system. Now at
DirectX 7 and DirectX 8, Microsoft is beginning to break the entry-level
barriers posed by earlier versions of DirectX, and hardware vendors are
beginning to work out hardware conflicts that have plagued this versatile API.
Along with the usual bug fixes, DirectX 7 introduced a few helper libraries
such as D3DX, which take away the repetitive initialization functions that made
DirectX difficult to use for first-timers. The next step, DirectX 8, provides a
slew of new features to the API, including an overall architecture redesign.
Let’s take a look at the history of DirectX to get a grasp of where it’s
When DOS was the operating system of choice, game developers enjoyed direct
access to the hardware for which they were developing. With this access to
interrupts, sound cards, input devices, and the VGA controller, developers
could get the hardware to do exactly what they wanted it to do. In fact, when
Windows 3.1 was released, developers stayed away because nobody wanted to deal
with the overhead that Windows created.
DOS, however, was not without problems. Hardware device support in DOS
became a nightmare, as hundreds of PC configurations became possible with the
ever-growing list of hardware available on the market. More time was being
spent programming support for the hardware to work with the game than
programming for the game itself!
Then Microsoft unleashed Windows 95 into the world with promises of a new
and different operating system. Windows 95 had much to offer over its DOS-based
Windows 3.1 predecessor. Plug and Play was introduced to make it simple for the
consumer to install the latest hardware, be that a video card, input device, or
sound card. The operating system introduced a new resource-handling system that
made device management easier and device independence more of a reality.
Windows 95 alone, however, still did not bring the performance enhancements
needed for game developers to develop for the Windows platform.
DirectX set out to change all this. The original developers began with the
simple goal of making Microsoft Windows a desirable platform for game
development. They determined that in order to do this, they would need to
create DirectX through fast, low-level libraries that allowed the developer to
maintain creative freedom over his games. Next, the DirectX developers aimed at
shifting the burden of hardware support from the game developer to the hardware
manufacture. This made much more sense, as hardware manufacturers are more
qualified to write drivers for their products than the game developer is.
Another important feature of DirectX would be the capability to coexist
peacefully with other Windows components, including the ability to run a normal
Windows application while a DirectX application ran in the background. Lastly,
DirectX would have the performance capable in DOS while meeting all the above
specifications. With this in mind, development of DirectX has taken off the
last several years as Microsoft has created one of the top APIs currently
available for developers. Now let’s take a look at how the DirectX developers
have actually put this API together.
DirectX uses two drivers, the hardware abstraction layer (HAL) and the hardware
emulation layer (HEL), to send requests to the hardware device. When DirectX is
initialized, it checks the hardware to see if the hardware supports certain
capabilities. If the hardware does support a certain capability, then the HAL
will be used to access that hardware function; otherwise, the HEL will be used
to emulate the capability through software. Figure 1 shows this a little
The DirectX HAL/HEL architecture.
As you can see, the HAL directly uses the hardware functionality for output
while the HEL bypasses the hardware and implements its own functionality. This
architecture allows for easier expandability in future hardware. For example,
let’s say you have a graphics card that supports 3D bump mapping, but it
doesn’t support 3D environment mapping. You just bought the latest game that
has both bump mapping and environment mapping in its 3D engine’s feature list.
In this case, the DirectX HAL would take advantage of the bump-mapping
capabilities while the HEL would provide the functionality needed for
environment mapping. If in the future you decide to get a new 3D graphics card
that supports both of these capabilities in its hardware, the DirectX HAL will
take control and you will experience the effects in the same game through
Another aspect of DirectX’s architecture is the various component APIs that
comprise it. These APIs have already been listed for you, so now let’s take a
more detailed look at each one and figure out which ones you will want to use.
DirectX Graphics is the complete integration of DirectDraw and Direct3D from
previous DirectX versions. Because we’re using OpenGL for graphics, we have no
need to discuss DirectX Graphics.
This is the audio component of DirectX. Now a combination of DirectSound and
DirectMusic in DirectX 8, DirectX Audio provides a complete system for
implementing a dynamic soundtrack that takes care of hardware acceleration,
Downloadable Sounds (DLS), DirectX Media Objects (DMOs), and advanced 3D
positioning effects. This component of the API is basically a mixing engine,
allowing for endless possibilities in 3D sound positioning and effects in games
and other multimedia. This book covers DirectX Audio for implementing audio in
your demos and games.
DirectInput provides the developer with an interface to myriad input
devices, including support for force feedback. This component bypasses the
Windows messaging system by working directly with device drivers, which in turn
provides the faster responsiveness required in games. You will be using
DirectInput to handle the input for all of your demos and games.
DirectPlay is a set of tools that simplify communications across networks,
the Internet, or modems. The tools allow game players to find game sessions
easily to help manage the flow between hosts and players.
DirectShow provides multimedia support for video files such as AVIs and
MPGs. This component of DirectX that was once an outside API is integrated with
the release DirectX 8.
DirectSetup provides a simple API for installing DirectX from your
customized application. With DirectX being a complex product, this component
greatly simplifies the process of installation.
In our next article, we will compare DirectX to OpenGL.
About the Authors
Kevin Hawkins is the CEO of GameDev.net, a development site on the
web for game programmers.
Dave Astle is the COO of GameDev.net where he acts as the chairman
and editor-in-chief. He is founder of Myopic Rhino games and is currently a
software engineer in Salt Lake City, Utah.
Andre’ LaMothe is the CEO of Xtreme Games LLC and series editor for
the Premier Press game development book series. He has worked in 2D/3D
graphics, artificial intelligence at NASA, compiler design, robotics
engineering, virtual reality, telecommunications, and has been a consultant to
various companies located in Silicon Valley. Andre’ is also the inventor of one
of the world’s first commercially available virtual reality games, CyberCafe,
created in the early ’90s.