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

Author Topic: Saving vertex Array as image  (Read 1502 times)

0 Members and 1 Guest are viewing this topic.

irr3vocableSake

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Saving vertex Array as image
« on: August 31, 2020, 07:44:55 am »
So, i have successfully used vertex array to draw graphics on the screen faster. Now is the time to save the contents of the window as an image. I tried to do the following but it results in either black image, blurry image, contents of the wrong frame etc.

           
sf::Vector2u windowSize = window.getSize();
           
            sf::Texture texture;
            texture.create(windowSize.x, windowSize.y);
            texture.update(window);

            sf::Image screenshot = texture.copyToImage();
            screenshot.saveToFile("maze_generator.png");

            window.close();
 

What options do i have while saving the vertex array as image
« Last Edit: August 31, 2020, 08:29:14 am by irr3vocableSake »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Saving vertex Array as image
« Reply #1 on: September 02, 2020, 12:48:19 am »
You're doing it pretty much how I would, so if you're getting unusual results it sounds like you're trying to capture the image after calling window.clear() but before window.display(), when the window is in a partially written state. Make sure the window is in a complete state before trying to update a texture from it, or you could potentially use a render texture, by drawing everything you want to capture to that first, once, then using renderTexture.getTexture().copyToImage() to save the file.