newbie texture question
Hi
I'm setting parts of a texture to transparent and saving as a .png file the only problem is that the transparent part of the texture is showing as black instead of transparent.
Any ideas on how to make it acutally transparent?
If it's anything like OpenGL I guess I have to enable blending or something.
Make sure you're specifying a texture format with an alpha channel when creating the texture and/or loading it (say via D3DXCreateTextureFromFileEx). Enable alphatesting if your file transparency is on/off or alphablending if the file has different degrees of transparency:
device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
device->SetRenderState(D3DRS_ALPHAREF, 1);
The previous 2 lines of code will cause all texels with alpha < 1 (i.e. = 0) to be transparent.
Make sure you have the texture stage states setup correctly, too (i.e. that the stage alpha takes the texture alpha into account, either by selecting it or modulating it with some other alpha).
device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
device->SetRenderState(D3DRS_ALPHAREF, 1);
The previous 2 lines of code will cause all texels with alpha < 1 (i.e. = 0) to be transparent.
Make sure you have the texture stage states setup correctly, too (i.e. that the stage alpha takes the texture alpha into account, either by selecting it or modulating it with some other alpha).
The most common texture stage and render states are as follows, usually they fit the requirements. You can play around with the parameters to achieve some cool effects :)
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);//an obvious one :)
device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);//an obvious one :)
device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement