SFML community forums

Help => Graphics => Topic started by: irr3vocableSake on August 31, 2020, 07:44:55 am

Title: Saving vertex Array as image
Post by: irr3vocableSake 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
Title: Re: Saving vertex Array as image
Post by: fallahn 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.