SFML community forums

Help => Graphics => Topic started by: jl1532 on June 07, 2021, 01:03:14 pm

Title: Getting a blank image
Post by: jl1532 on June 07, 2021, 01:03:14 pm
Hi, I would like to save a screenshot of the window but end up with getting a blank image
sf::RenderWindow win(sf::VideoMode(500, 1000), "Window 1");
sf::Texture texture;
sf::Image image;
texture.create(win.getSize().x, win.getSize().y);
texture.update(win);

 while (win.isOpen()) {
    sf::Event event{};
    while (win.pollEvent(event)) {
      if (event == sf::Event::Closed) {
        win.close();
      }
    }
    win.clear();
    win.draw(SomeShape);

    image = texture.copyToImage();                         // Assign texture to image
    image.saveToFile("../Saved Image/Logo.png");     // Able to generate the image file, but it's blank...

    win.display();
  }
}

I tried to put the two lines with comments at different position, for instance before win.clear or after win.display, but I still got a blank image.
Title: Re: Getting a blank image
Post by: jl1532 on June 07, 2021, 01:11:39 pm
Thankfully I think I figured it out. I move win.update(win) into the outer while loop, before win.clear();