Archived

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

Moe

can't get color keying to work

Recommended Posts

I have a simple direct draw 800*600 32bpp app running in fullscreen exclusive mode. I have bitmaps loaded onto 2 surfaces, one as a background and one as a cursor. I have the code for making the cursor bitmap appear at the correct mouse location, but I can''t get the color keying for the cursor to work. I want it so that the black square around the cursor isn''t there. I figured I would use source colro keying. Here is the code I am using to set the color key: //****do color keying here**** // get the pixel format DDPIXELFORMAT ddpf; ddpf.dwSize=sizeof(ddpf); lpddsprimary->GetPixelFormat(&ddpf); KeyColor = ddpf.dwGBitMask; // set color keys DDCOLORKEY key; key.dwColorSpaceLowValue = KeyColor; key.dwColorSpaceHighValue = KeyColor; lpcursor->SetColorKey(DDCKEY_SRCBLT, &key); lpddsback->SetColorKey(DDCKEY_SRCBLT, &key); Here is the code I use to blit the cursor: lpddsback->Blt(&cursor,lpcursor,NULL,DDBLT_WAIT | DDCKEY_SRCBLT,NULL); Now for some stupid wierd reason, the cursor bitmap doesn''t even appear. I have no idea and I am sick and tired of trying to make this stupid thing work. Can anyone here help me? Shrapnel Games

Share this post


Link to post
Share on other sites
key.dwColorSpaceLowValue = KeyColor;
key.dwColorSpaceHighValue = KeyColor;

I don''t remember at all. But you must specified only one (low or high), because if you give two value, this is only applied for chroma-key (many colors key).

So you code can be :
key.dwColorSpaceLowValue = KeyColor;

OR the next: (XOR)

key.dwColorSpaceHighValue = KeyColor;



-eng3d.softhome.net-

Share this post


Link to post
Share on other sites
hi -

I think you can try this and it may help

first:
DDCOLORKEY ddck;
// black color key
ddck.dwColorSpaceLowValue = RGB( 255, 255, 255 );
ddck.dwColorSpaceHighValue = RGB( 255, 255, 255 );
hret = DDSURFACE[numsurf]->SetColorKey( DDCKEY_SRCBLT, &ddck );
if ( FAILED( hret ) )
return Fail( hwnd, hret, "SetColorKey Failed" );

second:
lpddsback->Blt(&cursor,lpcursor,NULL,DDBLT_WAIT | DDBLT_KEYSRC,NULL);

I hope that helps

Share this post


Link to post
Share on other sites
The best way is to load your bitmap to a surface. Then lock the surface and read in the first value (which is normally the colour to be transparent) to a DWORD ''colour''(or whatever). Then just

key.dwColorSpaceLowValue = colour;
key.dwColorSpaceHighValue = colour;

Then set the colour key.

I think the problem is that your ''black'' may not be exactly 0,0,0. And yes, you do have to specify the low and high value.

Share this post


Link to post
Share on other sites
I don''t think that is the problem. Whenever I add the DDCKEY_SRCBLT to my Blt() function for the cursor bitmap, it disappears entirely.
Besides, I am pretty sure that my black is RGB(0,0,0). I used paint and took the black color in it and flood filled the areas I want keyed out. Not to mention I am using 32 bit color.

Shrapnel Games

Share this post


Link to post
Share on other sites
I don''t remember why but I create the (fullscreen) primary with:

ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT | DDSD_CKSRCBLT;

Maybe it''s the DDSD_CKSRCBLT flag...I think I had the same problem some time ago...

Share this post


Link to post
Share on other sites
I don' suppose you have the full source for the initialization of that program that you made that used that extra flag?
It still doesn't want to work properly. I see the background bitmap but not the cursor bitmap (again!!).
Shrapnel Games

Edited by - Moe on July 26, 2000 9:00:52 PM

Share this post


Link to post
Share on other sites
Try using this macro instead of RGB (It works with the 565 pixel format):

#define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 6) + ((r & 31) << 11))

It works for me, just set both low and high values to _RGB16BIT565(0,0,0) and everthing should work.
Not mine, got it from Andre Lamothe''s "Tricks of..."
If it doesn''t work let me know.

Share this post


Link to post
Share on other sites
i had a problem with color-keying once. i''m not exactly sure what was wrong, i was using the "DDSetColorKey" and "DDLoadSurface" that MS supplied in the examples. it worked fine if i loaded 8bpp bitmaps onto my 16 or 32bpp dest surfaces, but didn''t if i used any other bitmap format.
not sure if that helps any, but if your cursor has anything less than a couple million colors, try saving the cursor bitmap as a 256-color bitmap.



crazy166
some people think i'm crazy, some people know it

Share this post


Link to post
Share on other sites
I was playing around with the code last night, and get this! I used the Bltfast instead of blt and it half ways worked!! I am still having trouble getting it to get rid of all the black around the object, but I am thinking that it is just a problem with the bitmap or not clearing the memory first. Anyone had a similar experience to that?

Btw, I will have to give that macro thingy a try. Same with drpping the color depth of the cursor bitmap (oh, but 32bpp looks soo nice!)

Share this post


Link to post
Share on other sites
The black around the object is probably the bitmap.
It happend to me (ALOT) because of Paint Shop. Just make sure that the black around the object is totally black (RGB(0,0,0)).


Edited by - Tornado on July 27, 2000 4:33:28 PM

Share this post


Link to post
Share on other sites
I am really sure it is black. I opened it up in windows paint and used the black in there to make sure it was black. I think it is a problem with the color depth or something because when I drop it to 8bpp it comes out fine.

Shrapnel Games

Share this post


Link to post
Share on other sites
Color key can be a nightmare. You may not be aware of it, but most modern video cards DO NOT SUPPORT COLOR KEY. yup you read that right, they ''Fake'' the color key support by using alpha blending with one bit alpha. Sometimes this causes problems with certain cards, bitmap formats and color depths. Have a look at the technical articles on nVidias website, they have an article on how to do color keying for nVidia cards that explains why it can be such a problem.
Try running your app on a pc with a different video card, or change your drivers. I wouldnt be suprised if it suddenly worked.I had similar problems.
The general consensus amongst video card makers seems to be that people shouldnt use color key anymore, its described as legacy technology. bummer eh?

http://www.positech.co.uk

Share this post


Link to post
Share on other sites