Tricks of the Windows Game Programming Gurus:Advanced DirectDraw and Bitmapped Graphics

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

#### The Main DirectDraw Object

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

    HRESULT 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

    DDRAW_INIT_STRUCT(hel_caps);

    DDRAW_INIT_STRUCT(hal_caps);

    // make the call

    if (FAILED(lpdd->GetCaps(&hal_caps, &hel_caps)))

        return(0);

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

        } DDCAPS,FAR* LPDDCAPS;

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);

> Note: 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.

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

#### 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 `IDIRECTDRAWSURFACE4::GetCaps()`:

    HRESULT GetCaps(LPDDSCAPS2 lpDDSCaps);

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 `IDIRECTDRAWSURFACE4:: GetSurfaceDesc()`. It returns a `DDSURFACEDESC2` structure, which has a little more detail about the surface itself. Here’s the prototype:

    HRESULT GetSurfaceDesc(LPDDSURFACEDESC2 lpDDSurfaceDesc);

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

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.