can't get color keying to work

Started by
14 comments, last by Moe 23 years, 8 months ago
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
Advertisement
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-
-----------------------------------------------"Cuando se es peon, la unica salida es la revolución"
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
thats white. RGB(0,0,0) is black

Im Always Bored
--Bordem
ICQ: 76947930
Im Always Bored--Bordem ICQ: 76947930
Nope. Nothing there helped. How about someone post some source code (that works) of thiers on here. Maybe that could help. The DX SDK isn''t much help on this either.

Shrapnel Games
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.
-------------I am a Juggalo.
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
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...
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
Post some more of your initialization code.
-------------I am a Juggalo.

This topic is closed to new replies.

Advertisement