Jump to content
  • Advertisement
Sign in to follow this  
Stefan Fischlschweiger

[D2D] How to draw with transparency?

This topic is 1205 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

I've created a button texture for my game menus. It has partial transparency and is saved in DXT5 dds.

When I view it in Photoshop the transparency shows correctly, but when I draw it ingame with:

public void DrawBitmap(Bitmap1 bitmap, Rectangle rect, Vector2 position, float opacity = 1.0f)
        {
            if(bitmap == null)
                return;
            Begin();
            Context.Transform = Matrix3x2.Translation(position);
            Context.DrawBitmap(bitmap, rect, opacity, BitmapInterpolationMode.Linear);
            End();
        }

It if fully opaque, while it should actually blend with the menu background.

 

Bitmap loading is done using the following code:

public static Bitmap1 LoadBitmap(string filename, DeviceContext context)
        {
            var props = new BitmapProperties1();
            props.PixelFormat = new SharpDX.Direct2D1.PixelFormat(Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied);
            
            return Bitmap1.FromWicBitmap(context, LoadBitmap(filename), props);
        }

        private static BitmapSource LoadBitmap(string filename)
        {
            var d = new BitmapDecoder(
                Imgfactory,
                filename,
                DecodeOptions.CacheOnDemand             
                );

            var frame = d.GetFrame(0);

            var fconv = new FormatConverter(Imgfactory);

            fconv.Initialize(
                frame,
                PixelFormat.Format32bppPRGBA,
                BitmapDitherType.None, null,
                0.0, BitmapPaletteType.Custom);
            return fconv;
        }

Is there a flaw in my code? Or do I perhaps have to handle this totally different?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!