Sign in to follow this  
Lord_Taren

Texture transparency using Direct3D Sprite class

Recommended Posts

I am having trouble getting texture transparency to work using the Direct3D Sprite class. I have tried different file formats for the images. I have tried file formats that include the aplha channel and ones that don't. No matter how I try, the alpha channel is ignored. Here is a sample of the code I am using: xTmpTexture = TextureLoader.FromFile(GrafixEnv.Device, sTextureName, 0, 0, 1, 0, Direct3D.Format.A8R8G8B8,Direct3D.Pool.Managed, Direct3D.Filter.None, Direct3D.Filter.Point, 0, ref dxImageInfo); this.m_iWidth = dxImageInfo.Width; this.m_iHeight = dxImageInfo.Height; //* Begin the drawing sequence this.m_dxSprite.Begin(Direct3D.SpriteFlags.None); //* Draw the sprite this.m_dxSprite.Draw( (Direct3D.Texture)this.m_dxTexture, srcRect, new DirectX.Vector3(0, 0,0), this.m_v3Position, System.Drawing.Color.White.ToArgb()); this.m_dxSprite.End(); Is there some render state I need to set or is there something I am forgetting to do?

Share this post


Link to post
Share on other sites
For the Sprite flags you might want to try passing AlphaBlend (can't recall exact name, but it's in the docs).

Basically, it's being ignored because you specifically told it to by passing None. Fix that up and you should be good to go.

Share this post


Link to post
Share on other sites
I believe that when you call ID3DXSprite::Begin(), you need to specify the D3DXSPRITE_ALPHABLEND flag. The correct Managed syntax for this would be:

m_dxSprite.Begin( SpriteFlags.AlphaBlend );

This will automatically enable all of the alpha-blending renderstates that you need.

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