Original Post
Basicly I''m having a lot of trouble getting the thing to blt from the off screen surface to the back surface. I can copy and load and blt full screen backgrounds but thats all. Here is my code:
Any help is greatly appreciated.
--------------------------------------------------------------
The Code:
// \/---In a loop that occurs every frame
LPDIRECTDRAWSURFACE lpddsTest;
CreateBitmapSurface(lpddsTest, "aship.bmp", 128, 128);
RECT aRect;
SetRect(&aRect, 0, 0, 128, 128);
lpddsback->Blt(&aRect, lpddsTest, &aRect, DDBLT_WAIT, NULL);
lpddsTest->Release();
///////////////////////////////////////////////////////////
void CreateSurface(LPDIRECTDRAWSURFACE *lpSource, int xs, int ys)
{
DDSURFACEDESC ddsd;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = xs;
ddsd.dwHeight = ys;
lpdd->CreateSurface(&ddsd, lpSource, NULL);
}
////////////////////////////////////////////////////////////////
void DrawHBitmap(IDirectDrawSurface *lpSurface, HBITMAP hBitmap, int x, int y, int width, int height)
{
HDC hdcImage;
HDC hdc;
BITMAP bm;
if (lpSurface == NULL || hBitmap == NULL)
return;
lpSurface->Restore();
hdcImage = CreateCompatibleDC(NULL);
SelectObject(hdcImage, hBitmap);
GetObject(hBitmap, sizeof(bm), &bm);
width = width == 0 ? bm.bmWidth : width;
height = height == 0 ? bm.bmHeight : height;
lpSurface->GetDC(&hdc);
BitBlt(hdc, x, y, width, height, hdcImage, 0, 0, SRCCOPY);
lpSurface->ReleaseDC(hdc);
DeleteDC(hdcImage);
}
////////////////////////////////////////////////////////////////
void CreateBitmapSurface(LPDIRECTDRAWSURFACE lpSurface, char *fname, int xs, int ys)
{
HBITMAP hBitmap;
CreateSurface(&lpSurface, xs, ys);
hBitmap = LoadImage(NULL, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
DrawHBitmap(lpSurface, hBitmap, 0, 0, xs, ys);
DeleteObject(hBitmap);
}