D3DX is a set of wrapper classes for DirectX that can make it easier to work with.

D3DX Features
Sprites - D3DX makes it easy to blit a texture to the screen, with rotation, scaling, clipping and alpha blending.

Meshes - D3DX provides a D3DXMESH type that contains both data and methods for easily creating and working with meshes. Using this in conjunction with precreated 3D object files can make it very easy to drop 3D objects into your program.

Fonts - Fonts can be very difficult to use in DirectX; D3DX improves this by providing the D3DXFONT object, which can be attached to any system font. You can then print text anywhere to the screen in any color with a single function call.

There's more of course, including functions to create simple shapes (like cubes, spheres, teapots, etc) on the fly instead of loading them from 3D object files, calculating normals, planes, quaternions and matrices, and creating textures from just about any graphical file type or even a system surface (for animated textures).

Another thing D3DX provides is the CD3DApplication class. This is an entire D3DX program encapsulated into a single class, with a lot of functionality built in. You use it by deriving your own class from this one (typically called CMyD3DApplication) and overriding the following virtual functions:

ConfirmDevice() - called by the application whenever it needs to see if a certain function is supported by the current video card.

OneTimeSceneInit() - called once when the application starts up, therefore should contain initializations but shouldn't include anything that makes it necessary to call the function again.

InitDeviceObjects() - initializes all objects, both 3D and hardware, to get them ready for use. Called when the program starts but also called after the device is changed (you resized the window or changed video modes) or lost and regained (you Alt-Tabbed away from the application and then switched back).

InvalidateDeviceObjects() - marks all objects as invalid and not to be used in rendering. Used when the user Alt-Tabs away or the focus is otherwise lost.

RestoreDeviceObjects() - marks all device objects as valid again. The opposite of InvalidateDeviceObjects(), used when the focus is regained and it's time to start processing frames again.

FrameMove() - performs any operation on the 3D objects that should happen once per frame. Called once per frame.

Render() - renders the 3D objects to the screen. Called once per frame.

DeleteDeviceObjects() - deletes all device objects in preparation for program shutdown.

FinalCleanup() - performs any other tasks necessary for program shutdown.

When the application starts, the following functions are called in this order:

(ConfirmDevice() will probably be called by the constructor or OneTimeSceneInit(), but isn't actually part of the startup progression.)

When the rendering device is lost and regained (for any reason) the following functions are called to handle it:


When the application is shutting down, the following functions are called in this order:


The Cons
There are two problems I see with using D3DX.

The first is that D3DX deliberately hides some of the more esoteric features of DirectX in the process of making it easier to use. It is entirely possible to write a game using just D3DX, but if you want the whole power of DirectX you're going to want to eventually move beyond D3DX. This is relatively minor.

The second is that if you use CD3DApplication as the basis of your program, you have married it completely with DirectX; you can pretty much throw any hope of later adding OpenGL or other support out the window. If you're writing something that you want to turn into a generic game engine, starting with D3DX can lead to massive headaches later.

Using D3DX in your Projects
In order to use D3DX in your DirectX projects, you are going to have to set up a few things.

First, you'll need to add the D3DX8.LIB file to the libraries your program links to.

Second, you'll need to add the necessary D3DX files to your project. These files are not kept with the other DirectX header and source files; they are kept in (DirectX SDK Directory)\samples\Multimedia\Common. I personally copy the files I need out of this folder and put them in with the source files of my project; it makes compilation easier. You will also need to actually add the files to the project as well (I typically create a new folder in the project called Common and put them all in there rather than clutter up my Source folder with them).

Third, if you're starting from scratch and are using the DirectX 8.1 SDK, you can bypass all this setup by using the DirectX AppWizard that the SDK installs into Visual C++. Just start a new project and choose "DirectX Application" as the type. Pick the features you want and you will be presented with a D3DX application framework that uses the CD3DApplication class and supports everything you asked for. This can save you a lot of grunt-work programming.

Log in or registerto write something here or to contact authors.