Jump to content
  • Advertisement
Sign in to follow this  
Albeoris

How to draw a rectangle over a texture with half-transparency?

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

Hello,

 

I am trying to draw a rectangle over a texture:

spriteBatch.Begin();
texture.Draw(device, spriteBatch, Vector2.Zero, new Rectangle(0,0, texture.Width, texture.Height), 0, clipRectangle);
spriteBatch.End();

Brush selectedColorBrush = new SolidColorBrush(target2D, new Color4(new Color3(255,0,0), 50), null);

target2D.BeginDraw();
target2D.FillRectangle(rectangle, selectedColorBrush);
target2D.EndDraw();

But it drown without transparency:

bj96dmZ.png

 

What did I do wrong?

 

P.S. I cannot use a Bitmap class because "D2DERR_UNSUPPORTED_PIXEL_FORMAT/UnsupportedPixelFormat"

 

Thank you for your attention.

Edited by Albeoris

Share this post


Link to post
Share on other sites
Advertisement

Solved!

 

I do that over layers:

using (Layer layer = new Layer(target2D))
{
    LayerParameters layerParameters = new LayerParameters {ContentBounds = RectangleF.Infinite, MaskTransform = Matrix3x2.Identity, Opacity = 0.5f};
    target2D.PushLayer(ref layerParameters, layer);

    target2D.BeginDraw();
    target2D.FillRectangle(rectangle, selectedColorBrush);
    target2D.EndDraw();

    target2D.PopLayer();
}

MueqcjZ.png

 

Please corret me if I wrong and other good way is exists.

Edited by Albeoris

Share this post


Link to post
Share on other sites

Oh... What the shame... sleep.png

It's my fault. Color4 used components in the range 0.0...1.0f. But I set from 0 to 255. sleep.png

 

Without layers:

RVa5Xg6.png

Edited by Albeoris

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!