I''m having a problem with using a color key on a DirectDraw surface under 32 bit color.
To set a color key, I have a color match function that gets the closest color to the one requested then I use that color to set the color key. Here is the function:
static color_t win32_ColorMatch( LPDIRECTDRAWSURFACE a_Surface, color_t a_Color )
{
HDC hdc;
color_t rgb;
color_t Color = CLR_INVALID;
DDSURFACEDESC ddsd;
if( FAILED( a_Surface->GetDC( &hdc ) ) )
return 0;
rgb = GetPixel( hdc, 0, 0 );
SetPixel(hdc, 0, 0, a_Color );
a_Surface->ReleaseDC( hdc );
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );
if( FAILED( a_Surface->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) ) )
return 0;
Color = *( uint32* )ddsd.lpSurface;
Color &= ( 1 << ddsd.ddpfPixelFormat.dwRGBBitCount ) - 1;
if( FAILED( a_Surface->Unlock( &ddsd ) ) )
return 0;
if( FAILED( a_Surface->GetDC( &hdc ) ) )
return 0;
SetPixel( hdc, 0, 0, rgb );
a_Surface->ReleaseDC( hdc );
return Color;
}
color_t is a typedef and is a DWORD. This function works for 8, 16, and 24 bit color. However, it does not work for 32 bit color. Oh, and this is how I set the color key:
DDCOLORKEY ddck;
ddck.dwColorSpaceLowValue = Color;
ddck.dwColorSpaceHighValue = Color;
if( FAILED( m_Surface->SetColorKey( DDCKEY_SRCBLT, &ddck ) ) ) {
throw sys_Error( "gfx", GFX_ERR_SETCOLORKEY );
}
Any ideas? Thanks!
Josh
http://www.jh-software.com