Rookie
Rookie

Reputation: 4134

How to enable alpha blending on DirectX?

How to do this in DirectX?

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

Somehow i just cant seem to get it work. Im using code:

d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
d3ddev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
d3ddev->SetRenderState(D3DRS_ALPHAREF, (DWORD)50);
d3ddev->SetRenderState(D3DRS_ALPHATESTENABLE, 1);

But it will render my polygon with some sort of ghosted method, i can see through all my polygons! i just want to make the texture with alpha channel to show through those fully transparent pieces of texture. this works with alphatest, but it still shows black edges, so i guess the blending isnt enabled, even though i have set D3DRS_ALPHABLENDENABLE ! What im doing wrong?

Upvotes: 4

Views: 4047

Answers (1)

Rookie
Rookie

Reputation: 4134

instead of SRCCOLOR i needed to use SRCALPHA:

d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

Upvotes: 4

Related Questions