Search code examples
directxopacityalpha-transparency

How to have opacity on my texture in directx 9?


Been trying hard to find a solution to this, but the results are pretty bad.

Basically I want to draw a texture (it's made up of 2 triangles so it's a quad), and make them have alpha values (0-255, but 0-1 will do too). This is so that I can have that fade in/out effect when I wish.


Solution

  • Found my answer: Link to Source

    DWORD AlphaValue;
    AlphaValue = D3DCOLOR_ARGB(100,255,255,255);
    
    mpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
    mpDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    mpDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
    mpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    mpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    
    mpDevice->SetTextureStageState(0, D3DTSS_CONSTANT, AlphaValue);
    mpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CONSTANT);
    mpDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
    mpDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
    
    pMesh->Draw();