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

Author Topic: PNG with black background  (Read 2473 times)

0 Members and 1 Guest are viewing this topic.

tmac

  • Guest
PNG with black background
« on: October 21, 2010, 09:30:13 am »
Hi!

The PNG files I get from using sf::RenderWindow::Capture and then sf::Image::SaveToFile have no background, ie are transparent.

Can SFML instead create PNGs with black backgrounds? I didn't find it in the documentation. Perhaps I need to post-process with other tools?

-Torquil

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
PNG with black background
« Reply #1 on: October 21, 2010, 09:48:47 am »
How do you clear your RenderWindow? Can you show some relevant code?
Laurent Gomila - SFML developer

tmac

  • Guest
PNG with black background
« Reply #2 on: October 21, 2010, 06:10:32 pm »
I use SFML to generate a realtime video display which describe the state of a physics simulation. The display consists of lines and dots drawn using OpenGL.

Looking at this old code, I think I can describe the relevant parts as follows:

1) I have a derived class SFML which inherits from sf::RenderWindow. In its constructor, I execute

glEnable(GL_DEPTH_TEST)

2) At he beginning of each frame in the simulation, I execute

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

3) Thereafter, different gl* functions are executed to draw e.g. lines/dots/text etc.

4) Then I execute Display(), which my SFML class has inherited from RenderWindow.

The procedure 2-4 is run for each frame of the simulation. When I hit F1, I get a screenshot PNG file by executing

sf::Image Screen = Capture()
Screen.SaveToFile(s);

inside a keypress event-handler function, where s is the filename string.

I found that I can easily convert my PNGs using ImageMagick, so its no big deal. Something as simple as

convert 1.png -alpha off 2.png

if I remember correctly.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
PNG with black background
« Reply #3 on: October 21, 2010, 06:40:04 pm »
You never set the clear color?
Laurent Gomila - SFML developer

tmac

  • Guest
PNG with black background
« Reply #4 on: October 21, 2010, 07:39:13 pm »
Apparently not   :D

It sounds like that is something I should look up. I now see that this is mentioned elsewhere on this forum, so I'll educate myself by reading some thread(s). I know very little about these things. Just enough to make my own visualization work...

Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
PNG with black background
« Reply #5 on: October 21, 2010, 07:53:23 pm »
Well, it's as simple as
Code: [Select]
glClearColor(0, 0, 0, 1);
for opaque black.
Laurent Gomila - SFML developer