Archived

This topic is now archived and is closed to further replies.

Ilankt

2 key colors?

Recommended Posts

Ilankt    229
i want to do 2 key colors, in DX8 but i tried to do the "|" operation, but only the second color disapered... how i can do that?

Share this post


Link to post
Share on other sites
Joe Forhens    122
Since it''s color keying , every pixel that has that color will be completely transparent so you gain no benefits from having 2 colorkeys .. at least as far as i can think of .

Share this post


Link to post
Share on other sites
IFooBar    906
Say you want to make black and white the color keys, then you could lock the texture go through each pixel. If the pixel is blac or white, give it a 0 value so it dosnt show up. There is a function in d3dutil.h/.cpp called D3DUtil_SetColorKey()

  
HRESULT D3DUtil_SetColorKey( LPDIRECT3DTEXTURE8 pTexture, DWORD dwColorKey )
{
// Get colorkey''s red, green, and blue components

DWORD r = ((dwColorKey&0x00ff0000)>>16);
DWORD g = ((dwColorKey&0x0000ff00)>>8);
DWORD b = ((dwColorKey&0x000000ff)>>0);

// Put the colorkey in the texture''s native format

D3DSURFACE_DESC d3dsd;
pTexture->GetLevelDesc( 0, &d3dsd );
if( d3dsd.Format == D3DFMT_A4R4G4B4 )
dwColorKey = 0xf000 + ((r>>4)<<8) + ((g>>4)<<4) + (b>>4);
else if( d3dsd.Format == D3DFMT_A1R5G5B5 )
dwColorKey = 0x8000 + ((r>>3)<<10) + ((g>>3)<<5) + (b>>3);
else if( d3dsd.Format != D3DFMT_A8R8G8B8 )
return E_FAIL;

// Lock the texture

D3DLOCKED_RECT d3dlr;
if( FAILED( pTexture->LockRect( 0, &d3dlr, 0, 0 ) ) )
return E_FAIL;

// Scan through each pixel, looking for the colorkey to replace

for( DWORD y=0; y<d3dsd.Height; y++ )
{
for( DWORD x=0; x<d3dsd.Width; x++ )
{
if( d3dsd.Format==D3DFMT_A8R8G8B8 )
{
// Handle 32-bit formats

if( ((DWORD*)d3dlr.pBits)[d3dsd.Width*y+x] == dwColorKey )
((DWORD*)d3dlr.pBits)[d3dsd.Width*y+x] = 0x00000000;
}
else
{
// Handle 16-bit formats

if( ((WORD*)d3dlr.pBits)[d3dsd.Width*y+x] == dwColorKey )
((WORD*)d3dlr.pBits)[d3dsd.Width*y+x] = 0x0000;
}
}
}

// Unlock the texture and return OK.

pTexture->UnlockRect(0);
return S_OK;
}

You can use that to set the color key twice, once for each color.


And just out of curiosity...why do you need two color keys?


:::: [ Triple Buffer V2.0 ] ::::

Share this post


Link to post
Share on other sites