SFML community forums

Help => Graphics => Topic started by: Sakurazaki on June 07, 2013, 03:17:46 am

Title: [Solved] The best way to draw on texture
Post by: Sakurazaki on June 07, 2013, 03:17:46 am
Hi there,

To deploy some of my images on my HUD I want to load into a texture an image, and
then render into this texture some text and numbers, and then assign this texture to a
Rectangle shape to render it to the RenderWindow.

I declared a sf::RenderTexture but I don't see how can I load to this RenderTexture the image
I want to have as base, so I was wondering if there is any technique to do this, or I'm focusing
wrong the matter and there is another better approach.

I'd be very glad to learn and to be enlighten in this matter.

Thank you!
Title: Re: The best way to draw on texture
Post by: MrMuffins on June 07, 2013, 07:29:26 am
This is pretty much what RenderTexture is capable of.

Just draw your images to the rendertexture (Like your renderwindow), then pass the texture of it to your renderwindow (Or to the shape).

An example:


renderTexture.clear();

renderTexture.draw(Sprite1);
renderTexture.draw(Sprite2);
renderTexture.draw(Sprite3);
//...
renderTexture.display(); //call this otherwise the texture will be flipped on the Y axis

shapeRect.setTexture(&renderTexture.getTexture());

//draw
window.draw(shapeRect);

 
Title: Re: The best way to draw on texture
Post by: Sakurazaki on June 07, 2013, 09:01:57 pm
I see, ok thanks I somehow know how to handle it.

ありがとうございました!