texture with alpha

Started by
3 comments, last by UnrealSolo 16 years, 2 months ago
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
Advertisement
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
www.mwgames.com - my game projects websiteNimble2D Blog - Simple 2D Game Dev with VB.Net
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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
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.

This topic is closed to new replies.

Advertisement