SFML community forums

Bindings - other languages => DotNet => Topic started by: Robin on September 25, 2014, 05:05:38 pm

Title: Easier way to clear a specific area of a render target?
Post by: Robin 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
Title: Re: Easier way to clear a specific area of a render target?
Post by: Laurent 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)
Title: Re: Easier way to clear a specific area of a render target?
Post by: Robin 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.