SFML community forums

Help => Graphics => Topic started by: Folling on May 10, 2017, 06:56:34 pm

Title: How to reduce two draw calls into one
Post by: Folling on May 10, 2017, 06:56:34 pm
Hello everyone,

I have created my own class called SFMLButton which is supposed to, as the name implies function as a button.
Now an SFMLButton contains both a RectangleShape and a Text for the respective purposes.
The issue is, to draw this Button now I would have to call two separate draw calls.
window.draw(SFMLButton.shape) and window.draw(SFMLButton.text)
now I could override the draw function as SFMLButton is derived from Drawable.
Though I would still perform two draw calls per Button.
Is there a way to maybe create a texture which will contain both the shape and the text?

thanks in Advance
Folling
Title: Re: How to reduce two draw calls into one
Post by: Turbine on May 10, 2017, 07:55:34 pm
Yeah sure, use a sf:RenderTexture: https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1RenderTexture.php (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1RenderTexture.php)

As it's a sf:RenderTarget you may draw to the texture before drawing the texture to the window. You could draw a texture to another texture if you wanted even.