Thread: Key colour

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    87

    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)
    PuterPaul.co.uk - Portfolio site

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    87
    the ball texture
    PuterPaul.co.uk - Portfolio site

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    87
    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;
    }
    PuterPaul.co.uk - Portfolio site

  4. #4
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    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
    Muhammad Haggag

  5. #5
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128

    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 )
    Muhammad Haggag

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM