-
Key colour
I've set the background colour of my D3D app to white, i've also loaded a texture (ball.bmp) onto a set of vertices, and set the key colour to white also. Why is it then with the white pixels on the texture get drawn as black???
The texture is (ball.bmp)
The screenshot is (screenshot.gif)
-
-
Heres the intialisation code for the panel texture.
Code:
bool CHardball::InitGame()
{
//Setup panels for 2D
m_pPanel1 = new CPanel(pD3D->getD3DDevice(),16,16,pWindow->getWidth(),pWindow->getHeight());
m_pPanel1->setTexture("ball.bmp", D3DCOLOR_XRGB(255, 255, 255)); //Load the texture and set the key colour
return true;
}
bool CPanel::setTexture(const char *szTextureFilePath, DWORD dwKeyColour)
{
if(FAILED(D3DXCreateTextureFromFileEx(m_pD3DDevice, szTextureFilePath, 0, 0, 0, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, dwKeyColour, NULL, NULL, &m_pTexture)))
{
return false;
}
return true;
}
-
That's possibly happenning because D3DX's texture loading function goes through your texture replacing your colorkey with transparent black == 0x00000000
When you're rendering the texture without alpha blending, the white texels appears black ( because D3DX replaced them with transparent black, and transparency is shut down )
Make sure you set :
D3DRS_ALPHABLENDENABLE to true
D3DRS_SRCBLEND to D3DBLEND_SRCALPHA
D3DRS_DESTBLEND to D3DBLEND_INVSRCALPHA
-
I forgot something
Don't forget to set the texture stage states. Assuming you're using one texture at the stage 0 :
SetTextuerStageState( 0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1 )
SetTextureStageState( 0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE )