Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Easier way to clear a specific area of a render target?  (Read 3575 times)

0 Members and 2 Guests are viewing this topic.

Robin

  • Newbie
  • *
  • Posts: 29
  • I have no idea what I'm doing
    • View Profile
    • Crystalshire
Easier way to clear a specific area of a render target?
« on: September 25, 2014, 05:05:38 pm »
Afternoon all,

To cut down on drawing calls I'm playing around with the idea of rendering map sprites to a render target then drawing that to the main screen.

However as this is a map editor I need to be able to invalidate specific regions so I can re-draw the changes the user made.

Here's my current code:

Code: [Select]
var clearShape = new RectangleShape
{
Size = new Vector2f(32, 32),
FillColor = new Color(0, 0, 0, 1)
};
clearShape.Position = new Vector2f(0, 0);
_mapTexture.Draw(clearShape, new RenderStates(BlendMode.None));

It works very well, but I feel like there must be an easier (and less hacky. see: alpha value of 1 in colour) way to do this.

Any ideas?

Thanks,
Robin

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Easier way to clear a specific area of a render target?
« Reply #1 on: September 25, 2014, 06:41:26 pm »
Less hacky and more optimized:

Vertex[] quad = new Vertex[]
{
    new Vertex(new Vector2f(0, 0), new Color(0, 0, 0, 0)),
    new Vertex(new Vector2f(32, 0), new Color(0, 0, 0, 0)),
    new Vertex(new Vector2f(32, 32), new Color(0, 0, 0, 0)),
    new Vertex(new Vector2f(0, 32), new Color(0, 0, 0, 0))
};

mapTexture.Draw(Vertex, PrimitiveType.Quads, new RenderStates(BlendMode.None));

(sorry if the syntax is slightly wrong, I hope you get the idea)
Laurent Gomila - SFML developer

Robin

  • Newbie
  • *
  • Posts: 29
  • I have no idea what I'm doing
    • View Profile
    • Crystalshire
Re: Easier way to clear a specific area of a render target?
« Reply #2 on: September 25, 2014, 06:59:46 pm »
Less hacky and more optimized:

(sorry if the syntax is slightly wrong, I hope you get the idea)

Works like a charm.

Much appreciated.