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

SetColorKey problem

Started by
0 comments, last by CoolMike 24 years, 8 months ago
I am trying to implement transparency into my 16-bit DirectDraw game engine using color keying. I use the following function to set transparency:

///////////////////////////////////
void SetTransparentColor(
LPDIRECTDRAWSURFACE lpDDS,
int rgbRed, int rgbGreen, int rgbBlue )
{
DDCOLORKEY ddColorKey;

ddColorKey.dwColorSpaceLowValue =
RGB(rgbRed, rgbGreen, rgbBlue);
ddColorKey.dwColorSpaceHighValue =
RGB(rgbRed, rgbGreen, rgbBlue);

lpDDS->SetColorKey( DDCKEY_SRCBLT,
&ddColorKey);
}

///////////////////////////////////

I call this function (after I do all my DirectDraw initializations) like this:

SetTransparentColor( lpddsback, 0,0,0 );

During the game loop, I blit with the following syntax:

lpddsback->Blt (&destRect,lpddsOne,&srcRect,NULL,NULL);

The code builds fine, but that sprites in the game are not transparent, even though the background of my source bitmap is black.

I think it might be that I have to use the DDBLT_KEYSRC dwFlag to do this, like this:

lpddsback->Blt (&destRect,lpddsOne,&srcRect,DDBLT_KEYSRC,NULL);

But when I use this the sprite just doesn't show up at all. Does anybody know how to fix this?

Advertisement
Normally you set the color key on your sprite bitmaps, not your backbuffer as you appear to be doing. Just change your line

SetTransparentColor( lpddsback, 0,0,0 );

to whatever plain off screen surfaces you have and you should be fine.

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

This topic is closed to new replies.

Advertisement