SFML community forums

Help => General => Topic started by: Yaxlat on March 21, 2015, 10:51:30 pm

Title: Drawing onto PNG instead of onto window using SFML
Post by: Yaxlat on March 21, 2015, 10:51:30 pm
I am creating a platformer game using SFML, and my "Level Size" is a lot larger than my window size. So I am using sf::View to move around the view while I move.

What I do every frame is:
What I want to do now, however, is to draw each element onto an image (.png) file. A couple details:
How can I achieve this? Ideally I would like to run a function like this: exportPNG(string filename, level).
Thanks a lot!
Title: Re: Drawing onto PNG instead of onto window using SFML
Post by: G. on March 21, 2015, 11:57:28 pm
You can draw everything onto a transparent sf::RenderTexture, then get the sf::Texture of your render texture, then copyToImage() and saveToFile().

But if it is "a lot" larger than your window, you may be limited by the maximum texture size.
Title: Re: Drawing onto PNG instead of onto window using SFML
Post by: Yaxlat on March 22, 2015, 12:00:17 am
You can draw everything onto a transparent sf::RenderTexture, then get the sf::Texture of your render texture, then copyToImage() and saveToFile().

But if it is "a lot" larger than your window, you may be limited by the maximum texture size.
Ok, thanks a lot! I'll see what I can do, I haven't messed around with that yet. When I say a lot, I'm talking about 5000px maximum, so I think I'll be fine.
Title: Re: Drawing onto PNG instead of onto window using SFML
Post by: Yaxlat on March 22, 2015, 12:56:30 am
then get the sf::Texture of your render texture

How can I do this?
Title: Re: Drawing onto PNG instead of onto window using SFML
Post by: G. on March 22, 2015, 02:43:31 am
I'm pretty sure you'll find how if you take a look at the documentation of sf::RenderTexture.