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

Author Topic: Drawing onto PNG instead of onto window using SFML  (Read 2196 times)

0 Members and 1 Guest are viewing this topic.

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Drawing onto PNG instead of onto window using SFML
« 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:
  • I draw everything onto the window
  • Set the view to be part of the window
  • Run window.display()
  • Run window.clear()
What I want to do now, however, is to draw each element onto an image (.png) file. A couple details:
  • This image should be the same size as my "Level Size"
  • I don't want it zoomed in anyway - it should not be affected by my current window or view
  • Finally there are transparent parts of the image, because I have not drawn them onto my canvas. I do not want these black in my image, but rather transparent
How can I achieve this? Ideally I would like to run a function like this: exportPNG(string filename, level).
Thanks a lot!

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Drawing onto PNG instead of onto window using SFML
« Reply #1 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.

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Drawing onto PNG instead of onto window using SFML
« Reply #2 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.

Yaxlat

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Drawing onto PNG instead of onto window using SFML
« Reply #3 on: March 22, 2015, 12:56:30 am »
then get the sf::Texture of your render texture

How can I do this?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Drawing onto PNG instead of onto window using SFML
« Reply #4 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.