🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
DX7 Surface Ends up with garbage in it
HBITMAP hbm;
BITMAP bm;
DDSURFACEDESC ddsd;
IDirectDrawSurface *pdds;
HRESULT err;
hbm = (HBITMAP)LoadImage(
NULL, filename, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if (hbm == NULL)
return NULL;
//
// Get the size of the bitmap.
//
GetObject(hbm, sizeof(bm), &bm);
//
// Now, return to DirectX function calls.
// Create a DirectDrawSurface for this bitmap.
//
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
err = g->pDD->CreateSurface(&ddsd, &pdds, NULL);
if (FAILED(err))
{
g->TraceErrorDD(err);
TRACE(tracef," Creating surface\n");
return NULL;
}
err = g->DDCopyBitmap(pdds, hbm, 0, 0);
if(FAILED(err))
{
g->TraceErrorDD(err);
TRACE(tracef," On DDCopyBitmap\n");
return NULL;
}
DeleteObject(hbm);
return pdds;
Setting up DirectDraw Device:
// Set the "cooperative level" so we can use full-screen mode
hr = pDD->SetCooperativeLevel(ddWnd,
DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); // | DDSCL_NOWINDOWCHANGES
if (FAILED(hr)) {
TRACE(tracef,"Error setting Exclusive,Fullscreen mode\n");
pDD->Release();
return FALSE;
}
// Set 640x480x256 full-screen mode
hr = pDD->SetDisplayMode(640, 480, 8);
if (FAILED(hr)) {
TRACE(tracef,"Error setting display mode: %d\n", int(LOWORD(hr)));
pDD->Release();
return FALSE;
}
oh, and:
DDSURFACEDESC ddsd; // A structure to describe the surface we want
DDSCAPS ddscaps; // ??
HRESULT hr; // Holds return values for function calls
DDCOLORKEY ck;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |
DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
hr = pDD->CreateSurface(&ddsd, &pDDSPrimary, NULL);
if (FAILED(hr))
{
TRACE(tracef,"Error: pDD->CreateSurface (primary)\n");
TraceErrorDD(hr);
pDD->Release();
pDD = NULL;
return 1;
}
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
hr = pDDSPrimary->GetAttachedSurface(&ddscaps, &pDDSBack);
if (FAILED(hr)) {
TRACE(tracef,"Error: CreateSurface (back)\n");
TraceErrorDD(hr);
return 2;
}
ck.dwColorSpaceLowValue = RGB(0,0,0);
ck.dwColorSpaceHighValue = RGB(0,0,0);
pDDSPrimary->SetColorKey(DDCKEY_SRCBLT,&ck);
// success
return 0;
Ok, and the Blt setup and call:
NOTE: Check Surfaces Restores all lost surfaces.
menutl is the surface returned by the first call.
// RECT src;
HRESULT err;
CheckSurfaces();
// SetRect(&src,0,0,15,31);
err = g->pDDSBack->BltFast(100,50,menutl,NULL,
DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
if(FAILED(err))
{
g->TraceErrorDD(err);
TRACE(tracef," Blitting menutl\n");
}
NOTE: No Errors show up in my TRACE log file (and I know the TRACE works, because my comments show up.)
Also: Everything else works but the blt from the other surface (any of them). IE: I can draw text on screen, and fill the background to any color I want.
Wow is that ever a long post. Thanks in advance for all your help.
I got rid of LoadImage, and DDCopyBitmap, and read the bitmap file into structures, and copied it manually (1 byte at a time) into the locked surface.
(Oh, and I'm registered now too)
Here's the wierd part: When I blit it without a colorkey, it looks like garbage, but if I set a color key (RGB(0,0,0) to RGB(0,0,0)) It doesn't draw anything.
What's going on?
------------------
The last truth is that there is no magic(Feist)