Sign in to follow this  
Andregolas

drawing .dds textures with alpha channel

Recommended Posts

Andregolas    122
Hi all, I have a question concerning the .dds file format and its alpha channel. When I load my .dds texture (saved WITH alpha channel!) and draw it to a sprite, the transparent areas are white. How can I get the alpha channel in my program to get transparent areas? Thanks for your answers.

Share this post


Link to post
Share on other sites
Have you enabled alpha blending?

pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); // color * alpha
pDev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); // +
pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);// buffer * 1-alpha

I think the default TextureStageStates will use the alpha from your texture. If you've changed those states, make sure your alpha stages get the texture's alpha. For example:

pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); // tex
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); // *
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); // lighting

pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // tex alpha
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); // *
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); // material or vertex alpha

pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); // end
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); // end

Share this post


Link to post
Share on other sites
Andregolas    122
First of all: thanks for your answers =)

@51mon: I already saved my textures as A8R8G8B8 (DXT5)

@Namethatnobodyelsetook: Sorry we use C#. My Coder said that AlphaBlend IS enabled:

D3D_Device.RenderState.AlphaBlendEnable = true;

At texture loading he just uses the TextureLoader.FromFile(Device, PathToTexture) Method without any special parameters.

But we found a method to hide a color and I will replace the alpha channel with magenta to get a transparent background.

Although thanks for your efforts.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this