One of the main purposes of DirectX is to provide a standard way of accessing many different proprietary hardware devices. DirectX is comprised of application programming interfaces (APIs) that are grouped into two classes:

  1. The DirectX Foundation layer
  2. The DirectX Media layer

These APIs enable programs to directly access many of your computer’s hardware devices.

The DirectX Foundation layer

Foundation Layer automatically determines the hardware capabilities of the computer and then sets the program’s parameters to match. This allows multimedia applications to run on any  windows-based computer and at the same time ensures that the multimedia applications take full advantage of high-performance hardware.

Foundation Layer contains a single set of APIs that provide improved access to the advanced features of high-performance hardware, such as 3-D graphics acceleration chips and sound cards. These APIs control low-level functions, including 2-D graphics acceleration; support for input devices such as joysticks, keyboards, and mice; and control of sound mixing and sound output. The low-level functions are supported by the components that make up the DirectX Foundation layer:

Microsoft DirectDraw

The Microsoft DirectDraw API supports extremely fast, direct access to the accelerated hardware capabilities of a computer’s video adapter. It supports standard methods of displaying graphics on all video adapters, and faster, more direct access when using accelerated drivers. DirectDraw provides a device-independent way for programs, such as games and two-dimensional (2-D) graphics packages, and Windows system components, such as digital video codecs, to gain access to the features of specific display devices without requiring any additional information from the user about the device’s capabilities.

Microsoft Direct3D Immediate Mode

The Microsoft Direct3D Immediate Mode API (Direct3D) provides an interface to the 3-D rendering functions built into most new video cards. Direct3D is a low-level 3-D API that provides a device-independent way for applications to communicate with accelerator hardware efficiently and powerfully.

Direct3D provides application developers with many advanced features, such as:

  1. Switchable depth buffering (using z-buffers or w-buffers)
  2. Flat and Gouraud shading
  3. Multiple lights and light types
  4. Full material and texture support
  5. Robust software emulation drivers
  6. Transformation and clipping
  7. Hardware independence
  8. Full hardware acceleration on Windows 2000 (when the appropriate device drivers are available)
  9. Built-in support for the specialized CPU instruction sets, including Intel’s MMX and Pentium III architectures, and the 3DNow! architecture

Microsoft DirectSound

The Microsoft DirectSound API provides a link between programs and an audio adapter’s sound mixing and playback capabilities. It also enables wave sound capture and playback. DirectSound provides multimedia applications with low-latency mixing, hardware acceleration, and direct access to the sound device. It provides this feature while maintaining compatibility with existing device drivers.

Microsoft DirectMusic

The Microsoft DirectMusic API is the musical component of DirectX. Unlike the DirectSound API, which captures and plays digital sound samples, DirectMusic works with message-based musical data that is converted to digital audio either by your sound card or by its built-in software synthesizer. As well as supporting input in Musical Instrument Digital Interface (MIDI) format, DirectMusic provides application developers the ability to create immersive, dynamic soundtracks that respond to user input.

Microsoft DirectInput

The Microsoft DirectInput API provides advanced input for games and processes input from joysticks as well as other related devices including the mouse, keyboard, and other game controllers, such as force-feedback game controllers.

The DirectX Media layer works with the DirectX Foundation layer to provide high-level services that support animation, media streaming (transmission and viewing of audio and video as it is downloaded over the Internet), and interactivity. Like the DirectX Foundation layer, the DirectX Media layer is comprised of several integrated components that include:

Microsoft Direct3D Retained Mode

The Microsoft Direct3D Retained Mode API provides higher-level support for advanced, real-time, three-dimensional (3-D) graphics. Direct3D Retained Mode provides built-in support for graphics techniques like hierarchies and animation. Direct3D Retained Mode is built on top of Direct3D Immediate Mode.

Microsoft DirectAnimation

The Microsoft DirectAnimation API provides integration and animation for different types of media, such as two-dimensional images, three-dimensional objects, sounds, movies, text, and vector graphics.

Microsoft DirectPlay

The Microsoft DirectPlay API supports game connections over a modem, the Internet, or LAN. DirectPlay simplifies access to communication services and provides a way for games to communicate with each other, independent of the underlying protocol, or online service.

Microsoft DirectShow

The Microsoft DirectShow API plays multimedia files located in local files or on Internet servers, and captures multimedia streams from devices, such as video capture cards. DirectShow plays video and audio content compressed in various formats, including MPEG, audio-video interleaved (AVI), and WAV.

Microsoft DirectX Transform

The Microsoft DirectX Transform API enables application developers to create, animate, and edit digital images. DirectX Transform works with both two-dimensional (2-D) images and three-dimensional (3-D) images, which can be used to create stand-alone programs or dynamic plug-ins for Web graphics.

Before the release of Windows 95, most games were released for the DOS platform, usually using something like DOS4GW or some other 32-bit DOS extender to obtain access to 32-bit protected mode. Windows 95, however, seemed to signal the beginning of the end of the DOS prompt. Games developers began to wonder how they were going to write games optimally that would run under Windows 95 – games typically need to run in full-screen mode, and need to get as close as possible to your hardware. Windows 95 seemed to be “getting in the way” of this. DOS had allowed them to program as “close to the metal” as possible, that is, get straight to the hardware, without going through layers of abstraction and encapsulation. In those days, the extra overhead of a generic API would have made games too slow.

So Microsoft’s answer to this problem was a Software Development Kit (SDK) called DirectX. DirectX is a horrible, clunky, poorly-designed, poorly-documented, bloated, ugly, confusing beast of an API (Application Programming Interface) that has driven many a programmer to drink. It was originally purchased from a London company called RenderMorphics, and quietly released more or less as is as DirectX 2. DirectX 3 was probably the first “serious” release by Microsoft, who had now begun to actively push it as the games programming API of the future. Being the biggest software company on the planet, and being the developers of the Operating System that some 90% of desktop users were using, they succeeded. Hardware vendors quickly realised that following the Microsoft lead was the prudent thing to do, and everyone began to produce DirectX drivers for their hardware. In many ways this was a good thing for game developers.

A lot of improvements have been made to the original DirectX. For example, the documentation doesn’t suck as much as it originally did. Some of the poorly designed sections of the original API have been cleanup up and improved. Some of the really poorly designed sections of the original API have been removed.

What is the purpose of DirecX

One of the main purposes of DirectX is to provide a standard way of accessing many different proprietary hardware devices. For example, Direct3D provides a “standard” programming interface that can be used to access the 3D hardware acceleration features of almost all 3D cards on the market which have Direct3D drivers written for them. In theory this is supposed to make it possible for one application to transparently run as it is supposed to across a wide variety of different hardware configurations. In practice, it usually isn’t this simple.

One of the reasons it isn’t that simple, is that hardware (such as 3D graphics accelerators) normally only support a subset of the features available in DirectX, and you don’t really want to use a feature if it isn’t available in some sort of hardware accelerated form. To find out which features are available you have to query a device for a list of capabilities, and there can be many of these.The DirectX API is designed primarily for writing games, but can be used in other types of applications as well. The API at the moment has five main sections:

DirectX Components

DirectDraw2 dimensional graphics capabilities, surfaces, double buffering, etc
Direct3DA relatively extensively functional 3D graphics programming API.
DirectSoundSound; 3D sound
DirectPlaySimplifies network game development
DirectInputHandles input from various peripherals

Additionally, DirectX 6 introduces something called DirectMusic, which is supposed to make it easier for game developers to include music in their games so that the mood of the music changes depending on what type of action is going on in the game.

DirectX performance and hardware acceleration

Although the performance of Direct3D in software only is not too shabby, it doesn’t quite cut it for serious games. DirectX is designed with hardware acceleration in mind. It tries to provide the lowest possible level access to hardware, while still remaining a generic interface. Allowing functions such as 3D triangle drawing to be performed on the graphics card frees the CPU (Central Processing Unit) to do other things. Typical Direct3D hardware accelerators would also have at least 4 or preferably 16 or more Megabytes of onboard RAM to store texture maps (bitmapped images made up of small dots called “pixels”), textures, sprites, overlays and more.

DirectDraw and Direct3D are built as a relatively thin layer above the hardware, using what is called the DirectDraw “hardware abstraction layer” (HAL). For functionality not provided by a certain card, an equivalent software implementation would be provided through the “hardware emulation layer” (HEL).

DirectX and COM

The set of DirectX modules are built as COM (Component Object Model) objects. COM is yet another ugly broken interface from Microsoft – although newer versions of COM don’t suck as much as the earlier incarnations. Don’t get me wrong, I’m not against the existence of something that does what COM does – but the implementation leaves much to be desired. Anyway, a COM object is a bit like a C++ class, in that it encapsulates a set of methods and attributes in a single module, and in that it provides a kludgy sort of inheritance model, whereby one COM object can be built to support all the methods of it’s parent object, and then add some more.

You don’t need to know much about COM to use DirectX, so don’t worry too much about it. You do a little bit of COM stuff when initializing objects and cleaning them up, and when checking return values of function calls, but that’s more or less it.

Here's our list of top five game programming books you should read.

Game Engine Black Book: DOOM: v1.1

The book Game Engine Black Book: DOOM: v1.1 is just a masterpiece from Fabien Sanglard as it describes not only the details of how the code works, but also some interesting history and trivia. The description of hardware capabilities, audio/video interfaces, and design decisions behind them is quite interesting.

If you're not a programmer the book is still interesting - it explains lots of neat tricks, plenty of photos, quotes, and backstory about how the game was developed.

Game Programming Patterns

With over 85% 5-start reviews on Amazon, readers agree that Robert Nystrom's Game Programming Patterns is a must have for any software developer. It has a crystal clear look at how to be the benevolent architect of a very complicated software/game without getting lost.

The author presents the architecture of a game in an easy to understand matter not from an academic perspective but from experience. The book contains code examples written in C++, well organised and written so cleanly that it feels like pseudo-code.

Beginning C++ Through Game Programming

With Beginning C++ Through Game Programming, Michael Dawson builds your knowledge from the ground up. This book not only is easy to understand and teaches well, but it is focused on the very subject to learn C++ for game programming.

When it comes to game programming, C++ is the name of the game.

Blood, Sweat, and Pixels: The Triumphant, Turbulent Stories Behind How Video Games Are Made

This is highly recommend book for anyone who likes history of videos games, or just likes good stories. Blood, Sweat, and Pixels: The Triumphant, Turbulent Stories Behind How Video Games Are Made captures the complexity of game development that anyone can pick up and enjoy.

If you have even a passing interest in gaming be sure to pick this one up. (reader's comment)

Foundations of Game Engine Development - Volumes 1, 2

The volume 1 of the book discusses the mathematics needed by engineers who work on games or other virtual simulations. The volume 2 explores the vast subject of real-time rendering in modern game engines.

The book is packed with great C++ code snippets and examples. You have tried-and-true methods that can be incorporated into any game engine and source code is not specific to any API or framework.