Problems with alpha blending in DirectX9 for Windows 8 game RRS feed

  • Question

  • Hi!

    I am currently in the middle of writing a game engine in DirectX9 for Windows 8. However, I am experiencing some major problems with alpha blending.

    On one hand, I want to render all parts of the texture that are transparent with transparency. This is done by utilizing the texture's alpha channel:


    ->Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

    this->Device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

    this->Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);

    this->Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

    However, this produces an ugly black border about 1 pixel around all the transparent areas. How do I get rid of this?

    On the other hand, I also want to be able to set transparency for an entire object, utilizing only the alpha value in the color of the object:


    ->Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

    The problem is, these do not work well together. Using them both will produce a black background in the regions of the texture that are completely transparent. How do I get around this?

    Friday, October 26, 2012 8:25 AM


All replies

  • Nevermind, I solved it the minute I had posted this :)

    this->Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    	this->Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    	this->Device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

    Friday, October 26, 2012 8:41 AM
  • Hi Frostskin,

    The Building Windows Store games with DirectX forum is specifically about writing Windows Store games, which require DirectX 11.

    If you are writing a desktop game with older versions of DirectX then please post in the DirectX forums .


    Sunday, October 28, 2012 1:06 AM