SFML community forums
Help => General => Topic started by: Yaxlat on March 22, 2015, 01:07:56 am
-
I have written the following code:
string imageName = "levelImage";
sf::RenderTexture r;
for(vector<GameObject*>::const_iterator i = gameObjects.begin(); i != gameObjects.end(); ++i) {
(*i)->render(r);
}
r.getTexture().copyToImage().saveToFile(imageName);
Which should create an image of all my gameObjects. However, I am getting the error message: "failed to save image: "levelImage.png"" I am almost certain the problem is not within the for loop btw.
-
You're forgetting sf::RenderTexture::clear() and sf::RenderTexture::display().
They're very similar to a sf::RenderWindow.
-
You're forgetting sf::RenderTexture::clear() and sf::RenderTexture::display().
They're very similar to a sf::RenderWindow.
Actually I was forgetting sf::RenderTexture.create(); :)
clear and display are only for interacting with the screen, not saving an image
-
If you want a sf::RenderTexture to display the stuff you have drawn to it, you need to at least call display.
-
clear and display are only for interacting with the screen, not saving an image
I wonder where you've read that. All the doc says is that clear() and display() are needed for correct behaviour; stick to this.