DX7 Surface Ends up with garbage in it

Started by
5 comments, last by Strabbi 24 years, 5 months ago
haven't used colorkeys at all....but i'm well into a DirectX 6 project, using clippers and standard DirectDraw stuff a lot...so if you'd post the basic way your setting up your surface, your DirectDraw device, and then the Blt setup and call...i'd love to help ya find your problem.
Advertisement
Ok, Setting up offscreen surface:

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.

OK, I figured it out myself.

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)

--If Train A leave San Francisco at 8:30am EST travelling 25mph and Train B leaves Chicago at 1:30pm MST travelling at 40mph, and they're 3000 miles apart when they start, what is the capital of Bulgaria?
Just to let you know, DirectDraw doesn't do a real good job at emulating color keys. I've found that it only really works if the hardware supports it. I think source color-keying is supported in the HEL, but destination color-keying is not.
All I'm doing is source color keying, so that's ok with me.
--If Train A leave San Francisco at 8:30am EST travelling 25mph and Train B leaves Chicago at 1:30pm MST travelling at 40mph, and they're 3000 miles apart when they start, what is the capital of Bulgaria?
I'm writing a game (Isn't everyone in here) that (among other things), is required to read a .bmp file into an Offscreen Surface. It just ends up filled with random garbage when I Blt it to the screen.

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?

--If Train A leave San Francisco at 8:30am EST travelling 25mph and Train B leaves Chicago at 1:30pm MST travelling at 40mph, and they're 3000 miles apart when they start, what is the capital of Bulgaria?
Have you tried excluding the NOCOLORKEY statement. I never used it and and it worked.

------------------
The last truth is that there is no magic(Feist)

The last truth is that there is no magic(Feist)

This topic is closed to new replies.

Advertisement