SFML community forums

Help => Window => Topic started by: Haze on March 31, 2019, 07:12:59 pm

Title: Best way to save a screenshot
Post by: Haze on March 31, 2019, 07:12:59 pm
Hi,

I'm trying to catch up with last SFML releases, and noticed that RenderWindow::capture is now deprecated:
Quote
Use a sf::Texture and its sf::Texture::update(const Window&) function and copy its contents into an sf::Image instead.

My use case is saving to a image file what is currently rendered on a render window.

Is the following code the best approach for SFML >= 2.4?
sf::Texture texture;
texture.create(render_window.getSize().x, render_window.getSize().y);
texture.update(render_window);
if (texture.copyToImage().saveToFile(filename))
{
    std::cout << "screenshot saved to " << filename << std::endl;
}
 

Also, this seems like quite a common task. Maybe it should be added in the wiki?
Title: Re: Best way to save a screenshot
Post by: eXpl0it3r on March 31, 2019, 09:36:02 pm
Looks correct to me.

The Wiki is a community driven Wiki, would be great if you could add it! :)
Title: Re: Best way to save a screenshot
Post by: Haze on April 01, 2019, 09:28:59 am
Thanks for the confirmation.

I've added an entry to the Github wiki, under "Tutorials" section.

Nice to see all the core team is still active btw (I haven't used SFML since 2.1 release I think).