DDraw Interface

Describes the DDrawInterface and all its constants

Summary
DDraw InterfaceDescribes the DDrawInterface and all its constants
Enumerations
DDRAW_SURFACEFLAG_TYPUsed when calling DDrawInterface::CreateSurface
DDRAW_STATE_TYPDescribes the state of the DDrawInterface
Macros
DD_CLRClears out a DirectDraw structure and sets the dwSize member
DDrawInterfaceControls DirectDraw and provides a common interface to all of its functions.
Contructors
DDrawInterfaceAttempts to query an IDirectDraw7 interface and initialize it for use.
~DDrawInterfaceDoes nothing except keep track of an internal count of created classes
Display FunctionsAll the functions that setup and maintain the display.
EnumDisplayModesEnumerates the valid display modes for the device
InitDisplayInitializes the display for rendering.
RestoreDisplayRestores the display back to initialized settings.
ResizeBackBufferResizes the back buffer in the interface to match the window after a resize.
ShutdownInterfaceShutdown the interface.
Utility Functions
WaitForVerticalBlankWaits for the Vertical Blank to begin, then returns
CreateClipperCreates a clipper object using the provided parameters.
CreateSurfaceCreates a surface using the provided parameters.
Accessor Functions
getStateReturns the current state of the interface
TestStateTests the interface and makes adjustments to the state as neccessary
getDDrawGrabs the main DDraw inerface pointer.
getBackBufferGet the interface to the main BackBuffer.
getPrimaryBufferGet the interface to the Primary Buffer.
Exception Classes
xDDrawCreateFailedThrows when unable to query an interface to IDirectDraw7
XDDrawEnumFailedThrows when unable to enumerated the display modes
xDDrawBadModeThrows when attempting to initialize into a display mode that is not valid

Enumerations

DDRAW_SURFACEFLAG_TYP

Used when calling DDrawInterface::CreateSurface

DDRAW_SURFACEFLAG_VIDMEMVideo Memory
DDRAW_SURFACEFLAG_SYSMEMSystem Memory
DDRAW_SURFACEFLAG_WRITEONLYSurface is WriteOnly
DDRAW_SURFACEFLAG_READONLYSurface is optimized for reads.  This sets NONLOCALVIDMEMORY in the creation flags

DDRAW_STATE_TYP

Describes the state of the DDrawInterface

DDRAW_CLEANA clean state means that nothing has been done yet
DDRAW_ERRORThere has been an unrecoverable error
DDRAW_INVALIDThe DDraw Interface pointers are no longer valid
DDRAW_EXIT_FULLSCREENTemporary state while beginning to exit fullscreen mode
DDRAW_RESTOREReady to restore the DDrawInterface
DDRAW_WAITNot yet ready to retore the DDrawInterface
DDRAW_READYReady and initialized

Macros

DD_CLR

Clears out a DirectDraw structure and sets the dwSize member

DD_CLR(x)   memset(&(x),0,sizeof(x)); (x).dwSize=sizeof(x);

Parameters

xThis is the structure name that you want to be cleared

DDrawInterface

class DDrawInterface

Controls DirectDraw and provides a common interface to all of its functions.  Mainly used by startup to setup of the window and maintain a working runtime environment.

Summary
Contructors
DDrawInterfaceAttempts to query an IDirectDraw7 interface and initialize it for use.
~DDrawInterfaceDoes nothing except keep track of an internal count of created classes
Display FunctionsAll the functions that setup and maintain the display.
EnumDisplayModesEnumerates the valid display modes for the device
InitDisplayInitializes the display for rendering.
RestoreDisplayRestores the display back to initialized settings.
ResizeBackBufferResizes the back buffer in the interface to match the window after a resize.
ShutdownInterfaceShutdown the interface.
Utility Functions
WaitForVerticalBlankWaits for the Vertical Blank to begin, then returns
CreateClipperCreates a clipper object using the provided parameters.
CreateSurfaceCreates a surface using the provided parameters.
Accessor Functions
getStateReturns the current state of the interface
TestStateTests the interface and makes adjustments to the state as neccessary
getDDrawGrabs the main DDraw inerface pointer.
getBackBufferGet the interface to the main BackBuffer.
getPrimaryBufferGet the interface to the Primary Buffer.
Exception Classes
xDDrawCreateFailedThrows when unable to query an interface to IDirectDraw7
XDDrawEnumFailedThrows when unable to enumerated the display modes
xDDrawBadModeThrows when attempting to initialize into a display mode that is not valid

Contructors

DDrawInterface

DDrawInterface()

Attempts to query an IDirectDraw7 interface and initialize it for use.

Throws

xDDrawCreateFailed if unable to find IDirectDraw7.

~DDrawInterface

~DDrawInterface()

Does nothing except keep track of an internal count of created classes

Display Functions

All the functions that setup and maintain the display.  The modes are put into the control in the window provided and are enumerated into the following format.

Mode: WidthxHeightxBpp Hz

EnumDisplayModes

int EnumDisplayModes(const HWND hwnd,
const int rcResource) const

Enumerates the valid display modes for the device

Parameters

hwndHWND The window that will receive the display modes
rcResourceINT The control ID of the control that will be filled

Returns

False if successful, error code otherwise

Throws

<xDDrawEnumFailed> If unable to find any valid modes

InitDisplay

int InitDisplay()

Initializes the display for rendering.  It uses the information from CStartup to determine how to setup the mode.

Returns

False if successful, errorcode otherwise.

RestoreDisplay

int RestoreDisplay()

Restores the display back to initialized settings.  Do not use for changing Fullscreen to Windowed or it will crash.

Returns

False if successful, error code otherwise.

Throws

xDDrawBadMode if unable to use the specified display mode options in CStartup

ResizeBackBuffer

static int ResizeBackBuffer()

Resizes the back buffer in the interface to match the window after a resize.  This should not be used in Fullscreen mode or there will be problems!

Returns

False if successful, error code otherwise

Throws

xDDrawBadMode if unable to use the specified display mode options

ShutdownInterface

static void ShutdownInterface()

Shutdown the interface.  It will close all handles and release all memory that it has allocated.  It will put the interface into DDRAW_CLEAN

Utility Functions

WaitForVerticalBlank

void WaitForVerticalBlank(void) const

Waits for the Vertical Blank to begin, then returns

CreateClipper

LPDIRECTDRAWCLIPPER CreateClipper(const int num_rects,
const LPRECT clip_list) const

Creates a clipper object using the provided parameters.  It must be released before a device restore or shutdown.

Parameters

num_rectsINT This is the number of rectangles defined in the clip_list
clip_listLPRECT This is a pointer to an array of rectangles equal to num_rects

Returns

LPDIRECTDRAWCLIPPER with the provided parameters.  NULL if unsuccessful

CreateSurface

LPDIRECTDRAWSURFACE7 CreateSurface(
   const int width,  
   const int height,  
   const DWORD mem_flag = DDRAW_SURFACEFLAG_SYSMEM,
   const int bpp = 0
) const

Creates a surface using the provided parameters.  It must be released before a device restore or shutdown.

Parameters

widthINT The width of the surface
heightINT The height of the surface
mem_flagDWORD DDRAW_SURFACEFLAG_TYP flags describing how to store the surface in memory.  Defaults to DDRAW_SURFACEFLAG_SYSMEM.
bppINT Specifies the bits per pixel to use for the surface.  Defaults to 0 which will match the backbuffer’s bpp.

Returns

LPDIRECTDRAWSURFACE7 with the provided parameters.  NULL if unsuccessful

Accessor Functions

getState

static DDRAW_STATE_TYP getState()

Returns the current state of the interface

Returns

DDRAW_STATE_TYP with the current state

TestState

static DDRAW_STATE_TYP TestState()

Tests the interface and makes adjustments to the state as neccessary

Returns

DDRAW_STATE_TYP with the determined state

getDDraw

const LPDIRECTDRAW7 getDDraw(void) const

Grabs the main DDraw inerface pointer.  This will need to be encapsulated into a checkout class to avoid problems with exceptions and thread safety issues.

Returns

LPDIRECTDRAW7 for the current running mode.  NULL if none exists yet.  (which would be an assertion error)

getBackBuffer

const LPDIRECTDRAWSURFACE7 getBackBuffer(void) const

Get the interface to the main BackBuffer.  This should be put into a checkout class to avoid problems.

Returns

LPDIRECTDRAWSURFACE7 of the current back buffer.  NULL if errors.

getPrimaryBuffer

const LPDIRECTDRAWSURFACE7 getPrimaryBuffer(void) const

Get the interface to the Primary Buffer.  This should be put into a checkout class to avoid problems.

Returns

LPDIRECTDRAWSURFACE7 of the primary buffer.  NULL if errors.

Exception Classes

xDDrawCreateFailed

Throws when unable to query an interface to IDirectDraw7

class xDDrawCreateFailed : public std::exception

XDDrawEnumFailed

Throws when unable to enumerated the display modes

class xDDrawEnumFailed : public std::exception

xDDrawBadMode

Throws when attempting to initialize into a display mode that is not valid

class xDDrawBadMode : public std::exception
LPDIRECTDRAWSURFACE7 CreateSurface(
   const int width,  
   const int height,  
   const DWORD mem_flag = DDRAW_SURFACEFLAG_SYSMEM,
   const int bpp = 0
) const
Creates a surface using the provided parameters.
class DDrawInterface
Controls DirectDraw and provides a common interface to all of its functions.
DDrawInterface()
Attempts to query an IDirectDraw7 interface and initialize it for use.
~DDrawInterface()
Does nothing except keep track of an internal count of created classes
int EnumDisplayModes(const HWND hwnd,
const int rcResource) const
Enumerates the valid display modes for the device
int InitDisplay()
Initializes the display for rendering.
int RestoreDisplay()
Restores the display back to initialized settings.
static int ResizeBackBuffer()
Resizes the back buffer in the interface to match the window after a resize.
static void ShutdownInterface()
Shutdown the interface.
void WaitForVerticalBlank(void) const
Waits for the Vertical Blank to begin, then returns
LPDIRECTDRAWCLIPPER CreateClipper(const int num_rects,
const LPRECT clip_list) const
Creates a clipper object using the provided parameters.
static DDRAW_STATE_TYP getState()
Returns the current state of the interface
static DDRAW_STATE_TYP TestState()
Tests the interface and makes adjustments to the state as neccessary
const LPDIRECTDRAW7 getDDraw(void) const
Grabs the main DDraw inerface pointer.
const LPDIRECTDRAWSURFACE7 getBackBuffer(void) const
Get the interface to the main BackBuffer.
const LPDIRECTDRAWSURFACE7 getPrimaryBuffer(void) const
Get the interface to the Primary Buffer.
Throws when unable to query an interface to IDirectDraw7
class CStartup
Interface to control and query the running state of the program.
Throws when attempting to initialize into a display mode that is not valid
A clean state means that nothing has been done yet
Used when calling DDrawInterface::CreateSurface
System Memory
Describes the state of the DDrawInterface
Close