Color Keying State

Setting a color key instructs Direct3D to treat the key color as transparent. When Direct3D applies a texture that was created with the DDSD_CKSRCBLT flag to a primitive, all texels that match the key color are not rendered on the primitive. Note that any textures that were not created with the DDSD_CKSRCBLT flag will not display color-key effects, even if they contain the color key.

Set color keys with the IDirectDrawSurface4::SetColorKey method for the surface that will be using the color key (in this case, the render target surface). However, color keying can be toggled on and off by calling the IDirect3DDevice3::SetRenderState method. Set the first parameter to D3DRENDERSTATE_COLORKEYENABLE. Your application should set the second parameter to TRUE to enable color keying and FALSE to disable it. The default is FALSE.

// This code fragment assumes that lpD3DDevice3 is a valid pointer to
// a Direct3DDevice3.
 
// Disable color keying.
lpD3DDevice3->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, 
                             FALSE);