🎉 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!

DDSetColorKey in 16bit

Started by
8 comments, last by Bongo 24 years, 7 months ago
A couple of questions:

What does the SetColorKey function return? You need to check this. If it doesn't return DD_OK, you've got a problem. If would suggestion logging every function's return value somewhere to aid in your debugging.

What does your blitting code look like? I'm assuming you're using the DDBLT_KEYSRC flag in your Blt function call.

A little more info might help us in helping you.

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

Advertisement
Ok, i'm using the DDSetColorKey as defined in ddutil.cpp. I made a dinky file that contained whether my functions SUCCEEDed, or FAILED, and it shows that DDSetColorKey returned DD_OK. Here's what it looks like,
// note: i added comments (//) to clarify what each function does

=============================================
DDInit SUCCESS // sets up everything. screen width,height and bpp are #defines

DDCreateSurface SUCCESS // creates the lpddsring surface

DDSetColorKey SUCCESS // sets the RGB(250,0,218) into lpddsring surface

DDReLoadBitmap SUCCESS // loads the .dib into the lpddsring surface

=============================================
I made my .dib in PaintShopPro and it saves the .dib as 24bit, which doesn't seem to have any effect when displaying on a 16bit surface (cause the picture comes up fine...). Here's what my BltSurface functions looks like (i overloaded it):

=============================================
int BltSurface(LPDIRECTDRAWSURFACE7 lpdds, RECT dest, RECT source)
{
if(lpddsback->Blt(&dest,lpdds,&source,DDBLT_WAIT | DDBLT_KEYSRC,NULL)!=DD_OK)
return 0;

// everything ok
return 1;
}
/////////////////////////////////////////////
int BltSurface(LPDIRECTDRAWSURFACE7 source, int w, int h, int x, int y)
{
// w = width, h = height, x and y are where on the screen
RECT rcRect;

rcRect.left = 0;
rcRect.top = 0;
rcRect.right = w;
rcRect.bottom = h;
if(lpddsback->BltFast(x,y,source,&rcRect,DDBLTFAST_SRCCOLORKEY)!=DD_OK)
return 0;

return 1;
}

=============================================
I tried both functions, also by commenting the one that i wasn't testing, but neither seems to skip that color i chose. I wonder if it's the way PaintShopPro5 saves the RGB components...?

I'd put the .dib/.bmp file up here so you could test it out if you wanted to, if i knew how. Of course, i'd save it as .jpg first


Two things:

1) Converting from 24-bit to 16-bit will loose color precision. I.e. your color mask may end up beeing slightly different from what you intended. Use a color like pure blue instead (0,0,255)....

2) Jpeg is NOT a good idea when using color keying due to color distortion (I.e. posting a JPEG for people to test with will not give any good results )

/Niels

<b>/NJ</b>
Hrm, still didn't work. I just thought of manually getting the RGB values, like say in coord (1,1) of the surface, and log that into a file and see what i get, but i don't know how to get the RGB values from a surface....any suggestions?
You don't say what your RGB16 macro does.

DDSetColorKey(lpddsring,RGB16(240,0,218));

I hope it doesn't build an RGB565 color! Even though your surface is 16 bit, you must pass a 24 bit color to DDSetColorKey. Use the standard RGB macro instead. Look at DDUtil.cpp to see why.

On the other hand, when you use SetColorKey, you would pass it an RGB565 color. Stupid isn't it?

In 16bpp mode, the pixel RGB values are different according to card. You do not need to pass a 24 bit pixel, you need to use GetPixelFormat and make use of the bitmasks it returns. Otherwise, your transparent color would be different on all computers.

------------------
Visit the homepage of my (soon to be 'net multiplayer) Tank Game at http://members.home.net/chris-man

Visit the homepage of my (soon to be 'net multiplayer) Tank Game at http://members.home.net/chris-man

Try using the DDColorMatch function (provided in DDUtil.cpp which can be found with many of the samples). This function determines the value that the video card maps the 24bit color into for 16bit color.
And that's precisely the reason why you must pass DDSetColorKey a 24 bit color in standard GDI pixel format. DDSetColorKey invokes DDMatchColor itself to convert the 24 bit color you pass it into whatever pixel format your surface is using. Look at the source code!
ok, here's my dilemma

I'm currently creating a ddraw library, and i've run into a problem that i haven't figured out to fix (I'm using DirectX7 btw). I've made a program to make sure my library is working correctly.

The program currently sets up directdraw,creates a surface to hold a bitmap,loads the bitmap, sets the colorkey, blts the surface into lpddsback, and then flips.

I made RGB(250,0,218) as my colorkey in PaintShopPro5, and set up the color key like this:

DDSetColorKey(lpddsring,RGB16(240,0,218));
// lpddsring being the surface holding the .bmp, er .dib (i've tried both extensions)

Anyway, when i run it, i can still see the pink around the picture (a ring of fire). I even tried this setting:

DDSetColorKey(lpddsring,CLR_INVALID)

but still no success (and yes, the pink is in coord (0,0)). The blt function uses the DDBLT_KEYSRC flag too...

Can anyone help me out here?

Ok, i feel like screamin hehe. I got an idea from yall's posts, which was to write to a file what the value was at location 0,0 in my lpddsring surface. well i was tinkering around with it to get it working, when all of a sudden--it didn't blt the transparent color! Sheesh, i don't think i even changed the DDMatchColor function in ddutil besides making it log the value...

Well, thanks for the help guys hehe =).

This topic is closed to new replies.

Advertisement