Setting up DirectDraw 7
by Matthew Allen
MXF Entertainment
updated: 2/12/00
Click here for a txt file of the source code below.
Notes:
- In any program that you use the below code (or any DirectDraw code), be sure to use the header ddraw.h and the libraries dxguid.lib and ddraw.lib (in that order). To get these, get the DirectX SDK.
- You must do the Windows setup before the DirectDraw setup because setting the display mode requires passing a handle to your window (a HWND) to SetCooperativeLevel( ). Here is a tutorial on how to do that. I would suggest that you copy and paste the below code into the Windows tutorial code right after the part that you create, show, and update the window.
- FAILED( ) is a function defined in ddraw.h that checks the return values of the DirectX funtions to see if they failed. It returns zero for a SUCCESS and non-zero for a FAILURE. For example, in:
FAILED( DirectDrawCreate( NULL, &lpDDTemp, NULL ) ) if DirectDrawCreate( ) returns DD_OK (a value that indicates a success), then FAILED( ) will return non-zero.
LPDIRECTDRAW7 lpDD = NULL;
LPDIRECTDRAWSURFACE7 lpDDSPrimary = NULL;
LPDIRECTDRAWSURFACE7 lpDDSBack = NULL;
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;
if ( FAILED( DirectDrawCreateEx( NULL, ( LPVOID* )&lpDD,
IID_IDirectDraw7, NULL ) ) )
return FALSE;
if ( FAILED( lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE |
DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT ) ) )
return FALSE;
if ( FAILED( lpDD->SetDisplayMode( 800, 600, 16, 0, 0 ) ) )
return FALSE;
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
if ( FAILED( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) ) )
return FALSE;
if ( FAILED( lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpDDSBack ) ) )
return FALSE;
Discuss this article in the forums
Date this article was posted to GameDev.net: 7/5/2000
(Note that this date does not necessarily correspond to the date the article was written)
See Also:
DirectDraw
© 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
Comments? Questions? Feedback? Click here!
|