Sign in to follow this  

texture with alpha

This topic is 3569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im having trouble using a texture with a transparent background, the texture is stored as a .bmp file, with 8bpp and 256 color palette with rgba vales and loaded with :- Texture2D.FromFile(GraphicsDevice,filename); and I set graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; graphics.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add; but with textures of leaves the background comes out black, I assume its something like the texture isnt loading the alpha channel from the bmp file, or i need to set more drawing parameters, although I found the above render state parameters from another post, anyone know what else I need to do ? thanks

Share this post


Link to post
Share on other sites
I wasn't aware that BMP files (even ones with palettes) could store alpha values. I've only ever used color keys when using BMPs ... and used PNGs when a variable alpha value is needed.

-Matt

Share this post


Link to post
Share on other sites
You don't need the BlendFunction call as alpha-blending is defined as an addition.

Take a look at the SDK help file for alpha texture blending. Your problem may be lighting and/or what material you set for the render.

Also, ensure that your texture is sized correctly: powers of 2 for both width and height.

Share this post


Link to post
Share on other sites
ah well i have put the alpha value into the reserved entry in the bmp palette, as i thought thats what it was for, the source looks very much like a .bmp file, yet its embeded in a file with multiple other objects.

so i gues the load texture function is ignoring it.

is it easiest to make a png file with the alpha in it, given that i have a palette and a array of indexes, or to extract the alpha from the reserved entry and put that into the texture2d?

as i recal there was no easy way to make the bmp, i had to make my own header etc, im using c#

thanks

Share this post


Link to post
Share on other sites
well I changed to a png file, but I also found I had to make the image transparent rather than have an alpha channel, it now displays leafs of trees almost properly, the only thing i need to do is make sure any transparent textures are done last as it only works from certtain view angles, but ive run into a problem - I cant seem to find a way of determining if the image is transparent am I missing something simple ? theres a MakeTransparent but no IsTransparent function

ps oh i should mention im using xna

thanks.

Share this post


Link to post
Share on other sites

This topic is 3569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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