Jump to content

  • Log In with Google      Sign In   
  • Create Account

DX7 Surface Ends up with garbage in it


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Strabbi   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 10:04 AM

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?


Sponsor:

#2 Xai   Crossbones+   -  Reputation: 1459

Like
Likes
Like

Posted 19 November 1999 - 08:49 PM

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.

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 20 November 1999 - 07:05 AM

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.


#4 Strabbi   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 November 1999 - 08:08 AM

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)


#5 CodeDemon   Members   -  Reputation: 363

Like
Likes
Like

Posted 22 November 1999 - 08:13 AM

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.

#6 Strabbi   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 November 1999 - 09:55 AM

All I'm doing is source color keying, so that's ok with me.

#7 Yoshi   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 November 1999 - 10:04 AM

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)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS