Color Keys

 

Transparency

To use:

·       decide on a transparent color (color index, a number, or range of transparent colors), usually RGB (0,0,0) or index 0.

·       Create a DDCOLORKEY key

·       Set the transparent color range

·       Add DDSD_CKSRCBLT OR  DDSD_CKDESTBLT to the surface dwFlags

·       Then blt will copy everything but those pixels.

 

2 ways to perform transparency:

source transparency – designate colors in the source image that are not to be blitted.   USE THIS METHOD.

 

To set up source transparency use:

DDCOLORKEY key;   // define color key

 

// make index color 0 transparent

key.dwColorSpaceLowValue = 0; // starting transparent color

key.dwColorSpaceHighValue = 0; // ending transparent color

 

//set the key on source surface (usually backbuffer)

lpdsback->SetColorKey(DDCKEY_SRCBLT, &key);

 

·       Low & high values specify a range of transparent colors (set the same for single color).      

·       key.dwColorSpaceLowValue = RGB(128,0,0);
key.dwColorSpaceHighValue = RGB(255, 0,0);

·       if a color range is needed use:

    lpdsback->SetColorKey(DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &key);

 

destination transparency – designate colors in the destination image that can not be blitted over (replaced). HAL only feature.

 

Almost the same as source except you designate the colors that can be replaced:

DDCOLORKEY key;

key.dwColorSpaceLowValue = 0; // starting drawable color

key.dwColorSpaceHighValue = 0; // ending drawable color

//set the key on source surface (usually backbuffer)

lpdsback->SetColorKey(DDCKEY_SRCBLT, &key);