JavaScript EditorFree JavaScript Editor     Ajax Editor 

Main Page
  Previous Section Next Section

Getting the Lowdown on DirectDraw

As you've been learning, DirectDraw is a rather complex graphics system. It has a number of interfaces, each with numerous functions. The main point of DirectDraw is the utilization of hardware in a uniform manner. Therefore, it pays for game programmers to be able to query various DirectDraw interfaces for their states and/or capabilities so that the proper action can be taken. For example, when you're creating surfaces, you might want to first find out how much VRAM is available so you can optimize the creation order. Or maybe you want to use hardware rotation, but first you need to make sure it's available. The list of details that you might be interested in adding to the system your game is running goes on and on. Hence, there are a number of capability-testing functions, named GetCaps() or Get*() in general, available on each of the main interfaces. Let's take a look at the most useful GetCaps() functions.

The Main DirectDraw Object

The DirectDraw object itself represents the video card and describes the HEL and HAL. The function of interest is called IDIRECTDRAW7::GetCaps():

  LPDDCAPS lpDDDriverCaps,  // ptr to storage for HAL caps
  LPDDCAPS lpDDHELCaps);    // ptr to storage for HEL caps

This function can be used to retrieve both the HEL and HAL capabilities. Then you can review the DDCAPS structures returned for the data of interest. For example, here's how you would query for both the HAL and HEL:

DDCAPS hel_caps, hal_caps;

// initialize the structures

// make the call
if (FAILED(lpdd->GetCaps(&hal_caps, &hel_caps)))

At this point you would index into either hel_caps or hal_caps and check things out. Here's what DDCAPS looks like:

typedef struct _DDCAPS
    DWORD    dwSize;
    DWORD    dwCaps;                  // driver-specific caps
    DWORD    dwCaps2;                 // more driver-specific caps
    DWORD    dwCKeyCaps;              // color key caps
    DWORD    dwFXCaps;                // stretching and effects caps
    DWORD    dwFXAlphaCaps;           // alpha caps
    DWORD    dwPalCaps;               // palette caps
    DWORD    dwSVCaps;                // stereo vision caps
    DWORD    dwAlphaBltConstBitDepths;       // alpha bit-depth members
    DWORD    dwAlphaBltPixelBitDepths;       //  .
    DWORD    dwAlphaBltSurfaceBitDepths;     //  .
    DWORD    dwAlphaOverlayConstBitDepths;   //  .
    DWORD    dwAlphaOverlayPixelBitDepths;   //  .
    DWORD    dwAlphaOverlaySurfaceBitDepths; //  .
    DWORD    dwZBufferBitDepths;      // Z-buffer bit depth
    DWORD    dwVidMemTotal;           // total video memory
    DWORD    dwVidMemFree;            // total free video memory
    DWORD    dwMaxVisibleOverlays;    // maximum visible overlays
    DWORD    dwCurrVisibleOverlays;   // overlays currently visible
    DWORD    dwNumFourCCCodes;        // number of supported FOURCC codes
   DWORD    dwAlignBoundarySrc;      // overlay alignment restrictions
    DWORD    dwAlignSizeSrc;          //  .
    DWORD    dwAlignBoundaryDest;     //  .
    DWORD    dwAlignSizeDest;         //  .
    DWORD    dwAlignStrideAlign;      // stride alignment
    DWORD    dwRops[DD_ROP_SPACE];    // supported raster ops
    DWORD    dwReservedCaps;          // reserved
    DWORD    dwMinOverlayStretch;     // overlay stretch factors
    DWORD    dwMaxOverlayStretch;     //  .
    DWORD    dwMinLiveVideoStretch;   // obsolete
    DWORD    dwMaxLiveVideoStretch;   //  .
    DWORD    dwMinHwCodecStretch;     //  .
    DWORD    dwMaxHwCodecStretch;     //  .
    DWORD    dwReserved1;             // reserved
    DWORD    dwReserved2;             //  .
    DWORD    dwReserved3;             //  .
    DWORD    dwSVBCaps;               // system-to-video
                                      // blit related caps
    DWORD    dwSVBCKeyCaps;           //  .
    DWORD    dwSVBFXCaps;             //  .

    DWORD    dwSVBRops[DD_ROP_SPACE]; //  .
    DWORD    dwVSBCaps;               // video-to-system
                                      // blit related caps
    DWORD    dwVSBCKeyCaps;           //  .

    DWORD    dwVSBFXCaps;             //  .
    DWORD    dwVSBRops[DD_ROP_SPACE]; //  .
    DWORD    dwSSBCaps;               // system-to-system
                                      // blit related caps
    DWORD    dwSSBCKeyCaps;           //  .
    DWORD    dwSSBCFXCaps;            //  .
    DWORD    dwSSBRops[DD_ROP_SPACE]; //  .
    DWORD    dwMaxVideoPorts;         // maximum number of
                                      // live video ports
    DWORD    dwCurrVideoPorts;        // current number of
                                      // live video ports
    DWORD    dwSVBCaps2;              // additional
                                      // system-to-video blit caps
    DWORD    dwNLVBCaps;              // nonlocal-to-local
                                      // video memory blit caps
    DWORD    dwNLVBCaps2;             //  .
    DWORD    dwNLVBCKeyCaps;          //  .
    DWORD    dwNLVBFXCaps;            //  .
    DWORD    dwNLVBRops[DD_ROP_SPACE];//  .
    DDSCAPS2 ddsCaps;                 // general surface caps

Describing each field would require another book, so look it up in the SDK. Most of them are fairly obvious. For example, DDCAPS.dwVidMemFree is one of my favorite members because it indicates the amount of real VRAM that's available for use as surfaces.

There's also another function that I like to use, called GetDisplayMode(). It's useful in figuring out the mode that the system is in when running in windowed mode. Here's the prototype:

HRESULT GetDisplayMode(LPDDSURFACEDESC2 lpDDSurfaceDesc2);

And you've seen a DDSURFACEDESC2 structure before, so you know what to do there.


In most cases, all DirectX data structures are used to write as well as to read. In other words, you may set up a data structure to create an object, but when you want to know about an object via a GetCaps() call, the object will fill in the same data structure with the data of object.

Surfing on Surfaces

Most of the time, you couldn't care less about finding out the properties of a surface that you've created because you already know (you did create the darn thing)! However, the properties of the primary and back buffer surfaces are of utmost importance because they give you insight into the hardware properties of each. The function (or "method," if you're anal-retentive) that tells you about the general surface capabilities is IDIRECTDRAWSURFACE7::GetCaps():


This function returns a standard DDSCAPS2 structure, which you've seen before. Just open it up and pour it out!

The next surface-related function of interest is called IDIRECTDRAWSURFACE7:: GetSurfaceDesc(). It returns a DDSURFACEDESC2 structure, which has a little more detail about the surface itself. Here's the prototype:


There's also a IDIRECTDRAWSURFACE7::GetPixelFormat() method, but I've talked about this before, and GetSurfaceDesc() returns the pixel format in DDSURFACEDESC2. ddpfPixelFormat anyway.

Playing with Palettes

There's not much to talk about when it comes to palettes. DirectDraw only gives you a bit-encoded WORD that describes the abilities of any given palette. The function is called IDIRECTDRAWPALETTE::GetCaps() and is shown here:

HRESULT GetCaps(LPDWORD lpdwCaps);

lpdwCaps is a bit-encoded WORD with the values in Table 7.7.

Table 7.7. Possible Flags for Palette Capabilities
Value Description
DDPCAPS_1BIT Supports 1-bit color palettes.
DDPCAPS_2BIT Supports 2-bit color palettes.
DDPCAPS_4BIT Supports 4-bit color palettes.
DDPCAPS_8BIT Supports 8-bit color palettes.
DDPCAPS_8BITENTRIES Palette is an index palette.
DDPCAPS_ALPHA Supports an alpha component with each palette entry.
DDPCAPS_ALLOW256 All 256 colors can be defined.
DDPCAPS_PRIMARYSURFACE Palette is attached to primary surface.
DDPCAPS_VSYNC Palette can be modified synchronously with monitor's refresh.

      Previous Section Next Section

    JavaScript EditorAjax Editor     JavaScript Editor