As for having DirectX handle the clipping for me I had to change my code in DD_Init. I had the line -
G.lpDDSPrimary->SetClipper( lpClipper);
instead of
G.lpDDSBack->SetClipper( lpClipper);
The full changes I made are as follows:
Place the following in DD_Init.
LPDIRECTDRAWCLIPPER lpClipper; if (G.lpDD->CreateClipper(0, &lpClipper, NULL) !=DD_OK) return -99; lpClipper->SetHWnd(0, G.hWnd); G.lpDDSBack->SetClipper( lpClipper);
My current Gaim_Main code follows, this moves the Resource.bmp across the screen flashing different colours, with colourkey and clipping as it moves off the right of the screen. A viola - no crashing and no extra checking from me.
void Game_Main(){ RECT rectDest; DDSURFACEDESC2 ddsd2; PALETTEENTRY Pal; //Create a random colour Pal.peRed=rand()%256; Pal.peGreen=rand()%256; Pal.peBlue=rand()%256; //Assign this random colour to the palette index for the on-screen alpha-numeric text G.lpDDPalette->SetEntries(0, 93, 1, &Pal); //Get the description for the resource surface ZeroMemory(&ddsd2,sizeof(ddsd2)); ddsd2.dwSize = sizeof(ddsd2); G.lpDDSRes->GetSurfaceDesc(&ddsd2); //Clear back buffer EraseBackground(); static int i; //Prepare the destination rect for the entire resource surface rectDest.left = i; rectDest.top = 0; rectDest.right = ddsd2.dwWidth + i; // ensure the image stays the desired width, without the +1 the image shrinks in width rectDest.bottom = ddsd2.dwHeight; i++; //increment i DDBLTFX ddbltfx; ZeroMemory(&ddbltfx, sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); //fill with black ddbltfx.ddckSrcColorkey; G.lpDDSBack->Blt(&rectDest,G.lpDDSRes,NULL, DDBLT_KEYSRC | DDBLT_WAIT, &ddbltfx); //Flip the surface G.lpDDSPrimary->Flip(NULL,0);}
Hope some of you find this useful and interesting.
Now on to playing with image transfer.
**Knowledge is Power**