Environment: Windows 95/98/2000, DirectX 3-8, Visual C++ 6
CDX is a free GDK (Game Development Kit) which is comprised of a set of C++ wrapper classes for writing Windows games. It is built on top of Microsoft Windows and DirectX technology and offers simple to use C++ wrappers for all aspects of game development. This includes things like sprites, tiles, scrollable maps, alpha blending and even 3D primitives (using Direct3D).
CDX takes care of the low-level details of using DirectX, providing you with an easy to use toolkit for implementing your own games using simple yet flexible C++ classes. With only 2 dozen classes, CDX is quick to learn and easy to use.
These are the main classes that make up CDX. There are a few more (like file
and image handling, tiles, sprite lists, and resource files) but these are the ones you’ll primarily use.
is a class wrapper for DirectInput and contains functions to receive
data from the mouse, keyboard and joystick.
is derived from CDXSurface
and allows you to do scrollable side-shooter games.
|CDXMap||CDXMap allows you to render tile based maps like those
seen in games like StarCraft and Age of Empires.
|CDXMapCell||CDXMapCell is an overridable class that lets you store
whatever information you want in each map tile.
allows you to load and play MIDI files for the music in your game.
allows you to load and play audio CD files for the music in your game.
is the primary object of the library and every program that uses CDX
must include a CDXScreen
is a simple wrapper for a DirectSound object.
|CDXSprite||CDXSprite contains the data and functions required to
display animated sprites.
|CDXSurface||CDXSurface is the class that lets you access DirectDraw
surfaces. Two of these are automatically created in the CDXScreen class.
Screen Flipping Example
CDX is made up of some very simple classes to use and learning them is very easy. The main class, CDXScreen, handles all aspects of screen drawing. Below is a very simple, but complete, example of using CDXScreen in a Win32 application. The example is the same as the long-winded DirectX sample that Microsoft provides to show you how to do page flipping. This example shows you how little code is needed to accomplish the same task and can be a starting point for more complex applications and games.
#define CDXINCLUDEALL // include all headers
CDXScreen * Screen = 0; // The screen object, every
// program must have one
// remember to set all CDX objects
// to 0 when you declare them!
int Toggle = 0; // flag for the screen color
#define TIMER_ID 1 // variables used for the timer
#define TIMER_RATE 500
#define NAME "CDXExample"
#define TITLE "CDX Example"
long PASCAL WinProc(HWND hWnd,
WPARAM wParam, LPARAM lParam)
if( Toggle ) // fill the screen depending
// on toggle flag
Toggle = 0;
Toggle = 1;
Screen->Flip(); // flip back and front buffers
case VK_ESCAPE: // if ESC key was hit, quit program
PostMessage(hWnd, WM_CLOSE, 0, 0);
SAFEDELETE( Screen ); // delete the screen object
PostQuitMessage(0); // terminate the program
return DefWindowProc(hWnd, message, wParam, lParam);
BOOL InitApp(HINSTANCE hInst, int nCmdShow)
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WinProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInst;
WndClass.hIcon = LoadIcon(0, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(0, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WndClass.lpszMenuName = NAME;
WndClass.lpszClassName = NAME;
// create a window which covers the whole screen
// this is needed for fullscreen CDX apps
hWnd = CreateWindowEx(
// when hWnd = -1 there was an error creating the main
// window CDXError needs a CDXScreen object, if there is
// none at this early program stage, pass it NULL
CDXError( NULL , "Could not create the main window" );
// show the main window
// Create the CDXSreen object
Screen = new CDXScreen();
if(FAILED(Screen->CreateFullScreen(hWnd, 640, 480, 8)))
CDXError( NULL , "Could not set video mode 640x480x8" );
// Create our timer for flipping the screen display
SetTimer(hWnd, TIMER_ID, TIMER_RATE, NULL);
int PASCAL WinMain( HINSTANCE hInst,
CDXError( NULL , "Could not initialize CDX application");
if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
if(!GetMessage(&msg, NULL, 0, 0 ))
Essentially, you create the CDXScreen object, draw to it and then call the Flip() method to reveal your drawing to the user.
Using CDX with MFC
If you don’t want to write a standard Windows application with all those message handlers and case statements, you can use MFC with CDX. First, somewhere in your initialization code you need to create your CDXScreen object. This can be done in your own function or in the OnCreate method of your MainFrame.
HWND hWnd = AfxGetMainWnd()->m_hWnd;
Screen = new CDXScreen();
Then create a timer to handle the flipping of the screen and in the OnTimer method, do the page flipping.
void CMainFrame::OnTimer(UINT nIDEvent)
Screen->Fill(4); // Fill the back buffer red
Toggle = FALSE;
Screen->Fill(1); // Fill the back buffer blue
Toggle = TRUE;
Screen->Flip(); // Flip the back buffer to the front
That’s all it takes to get up and running with CDX! So if you’re interesting in writing apps or games using DirectX but are daunted by the complexity that’s involved in getting into DirectX programming give CDX a try!
The CDX Website can be found