Could someone kindly tell me why this doesn't work, and if it is considered a bug or not?
The following code
does not correctly take a screenshot, the PNG file rendered is blank with RGBA (0, 0, 0, 0).
I have the following code:
#include <SFML/Graphics.hpp>
const int ScreenWidth = 3000/4;
const int ScreenHeight = 2000/4;
int main()
{
sf::RenderWindow window(sf::VideoMode(ScreenWidth, ScreenHeight), "SFML Animation"/*, sf::Style::None*/);
sf::RectangleShape rect(sf::Vector2f(100, 100));
rect.setPosition(sf::Vector2f(100, 100));
while(window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Blue);
window.draw(rect);
window.display();
//static int i = 0;
//if (i++ > 10)
//{
sf::Image screenshot = window.capture();
screenshot.saveToFile("test_big000.png");
return 0;
//}
}
}
If I uncomment the last lines to be the following, to allow more frames to be processed before a screenshot,
a correct screenshot is made:
static int i = 0;
if (i++ > 10) // just to make it have to process the loop a few times
{
sf::Image screenshot = window.capture();
screenshot.saveToFile("test_big000.png");
return 0;
}
Short version:Why does the capture() function not work on the first frame of the program?
Is this intended behavior? Couldn't find anything with search to verify this claim.
Also note that the screenshot.saveToFile() is returning
true.
I'm on Windows 7, if that matters, using SFML 2.2 compiled from github about a week ago.