Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Bongo

DDSetColorKey in 16bit

This topic is 6834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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 =).

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!