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

Author Topic: Getting a blank image  (Read 2304 times)

0 Members and 1 Guest are viewing this topic.

jl1532

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Getting a blank image
« 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.

jl1532

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Getting a blank image
« Reply #1 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();

 

anything