CDX Game Development Kit

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

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.

The Classes

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.

CDXInput CDXInput is a class wrapper for DirectInput and contains functions to receive data from the mouse, keyboard and joystick.
CDXLayer CDXLayer 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.
CDXMusic CDXMusic allows you to load and play MIDI files for the music in your game.
CDXMusicCd CDXMusicCd allows you to load and play audio CD files for the music in your game.
CDXScreen CDXScreen is the primary object of the library and every program that uses CDX must include a CDXScreen object.
CDXSound CDXSound 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.

#include <windows.h>
#include <windowsx.h>
#include <stdio.h>

#define CDXINCLUDEALL       // include all headers
#include <CDX.h>

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,
                    UINT message,
                    WPARAM wParam, LPARAM lParam)
     case WM_TIMER:  
        if( Toggle )        // fill the screen depending
                            // on toggle flag
          Toggle = 0;
          Toggle = 1;
        Screen->Flip(); // flip back and front buffers

     case WM_KEYDOWN:
           case VK_ESCAPE: // if ESC key was hit, quit program
             PostMessage(hWnd, WM_CLOSE, 0, 0);

     case WM_DESTROY:    
        SAFEDELETE( Screen );   // delete the screen object
        PostQuitMessage(0);     // terminate the program
  return DefWindowProc(hWnd, message, wParam, lParam);

BOOL InitApp(HINSTANCE hInst, int nCmdShow)
  HWND hWnd;
  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
  ShowWindow(hWnd, nCmdShow);

  // 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

  return TRUE;

int PASCAL WinMain( HINSTANCE hInst,
                    HINSTANCE hPrevInst,
                    LPSTR lpCmdLine,
                    int nCmdShow)
  MSG msg;

  if(!InitApp(hInst, nCmdShow))
     CDXError( NULL , "Could not initialize CDX application");

     if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
        if(!GetMessage(&msg, NULL, 0, 0 )) 
          return msg.wParam;
     else WaitMessage();

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.

BOOL CMainFrame::InitDirectDraw()
  HWND hWnd = AfxGetMainWnd()->m_hWnd;
  Screen = new CDXScreen();
  return TRUE;

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!


Download setup program (includes demos and source) - 2.5 Mb
The CDX Website can be found here


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date