2 key colors?

Started by
5 comments, last by Ilankt 20 years, 11 months ago
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?
How appropriate, you fight like a cow!
Advertisement
please?
How appropriate, you fight like a cow!
Simple answer: you can''t. You''re gonna have to do the conversion to the required format yourself.

Kippesoep
Why do you need two keys? If we know that, perhaps we can offer alternatives.
Larry Johnson - Head flunky in charge of diddly-squat.www.sillisoft.com
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 .
Thank you all :)
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 ] ::::
[size=2]aliak.net
for black and white colors :-)
thanks!
that''s great.
How appropriate, you fight like a cow!

This topic is closed to new replies.

Advertisement