Howdy!
I'm having a bit of trouble with my DirectDraw clipper. The code compiles fine and runs without a hitch; however, it doesn't work. That is, there is no clipping! I get the exact same behavior as when I have no clipper used. It's all very mysterious as I've compared my code with dozens of others' that work, yet I can't find any differences in mine. I've tried to reduce my relevant code to as little as possible. Here is the function that initializes all my DirectX Stuff and returns the hWnd (minus some error-catching calls to simplify things):
And here is how it's called:
I'm having a bit of trouble with my DirectDraw clipper. The code compiles fine and runs without a hitch; however, it doesn't work. That is, there is no clipping! I get the exact same behavior as when I have no clipper used. It's all very mysterious as I've compared my code with dozens of others' that work, yet I can't find any differences in mine. I've tried to reduce my relevant code to as little as possible. Here is the function that initializes all my DirectX Stuff and returns the hWnd (minus some error-catching calls to simplify things):
Code:
int InitDirectDraw(HWND hWnd)
{
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;
HRESULT hRet;
// Create the main DirectDraw object.
hRet = DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL);
if( hRet != DD_OK ) return -1;
// Get exclusive mode.
hRet = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_ALLOWREBOOT);
if( hRet != DD_OK ) return -2;
// Set the video mode to 640x480x16.
hRet = lpDD->SetDisplayMode(640, 480, 16, 0, 0);
if( hRet != DD_OK ) return -3;
// Prepare to create the primary surface by initializing
// the fields of a DDSURFACEDESC2 structure.
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;
// Create the primary surface.
hRet = lpDD->CreateSurface(&ddsd, &lpDDSFront, NULL);
if( hRet != DD_OK ) return -1;
// Get a pointer to the back buffer.
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
hRet = lpDDSFront->GetAttachedSurface(&ddscaps, &lpDDSBack);
if( hRet != DD_OK ) return -1;
// Clipper Initialization
// Create the clipper using the DirectDraw object
lpDD->CreateClipper(0, &lpDDClipper, NULL);
// Assign your window's HWND to the clipper
lpDDClipper->SetHWnd(0, hWnd);
// Attach the clipper to the primary surface
lpDDSFront->SetClipper(lpDDClipper);
return 0;
}
Code:
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
{
hInst = hInstance;
hWnd = InitWindow(hInst, nCmdShow);
if(!hWnd) return -1;
if(InitDirectDraw(hWnd) < 0)
{
CleanUp();
MessageBox(hWnd, "Could not start DirectX engine in your computer. Make sure you have at least version 7 of DirectX installed.", "Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
. . .
CleanUp();
return 0;
}
Comment