I started learning SFML from SFMLCoder, and noticed that SFML interface changed, so I switched Image with Texture. This is lesson 2, so I didn't get very far
. The program worked, but I couldn't get a screenshot, so I googled, and found out, that I need an sf::Image and Window.Capture(). The program compiles, and runs, but it says that screenshot failed to save. My guess is that screenshot image is empty, but I am really new to SFML and I finished chapter 13 in Prata's book, so I am new to C++, too. I'd appreciate if someone took a look at the code and told me what to change and why. Sry if this has been asked 1000 times already.
#include <SFML/Graphics.hpp>
int main()
{
sf::VideoMode VMode(800, 600, 32);//Create Window
sf::RenderWindow Window(VMode, "Empty Window");
sf::Texture Image;//Create image
if (!Image.LoadFromFile("cake.png"))//Add a meme
return 1;
sf::Sprite Sprite2;//Make a sprite
Sprite2.SetTexture(Image);//Adjust it as I want
Sprite2.SetPosition(0.0f, 0.0f);
Sprite2.SetScale(0.0f, 0.0f);
Sprite2.Resize((float)VMode.Width, (float)VMode.Height);
Sprite2.SetColor(sf::Color::Red);//Paint it with blood!!!!
sf::Image Screenshot;//Image to store the screenshot
while (Window.IsOpened())//If it is open
{
sf::Event Event;
while (Window.PollEvent(Event))
{
switch (Event.Type)
{
case sf::Event::Closed://Check if it has been closed
Window.Close();
break;
default:
break;
}
}
Window.Clear(sf::Color(0,255,127));//Color it
Window.Draw(Sprite2);//Draw the sprite
Window.Display();//Display the window
Screenshot = Window.Capture();//Store screen in image
}
Screenshot.SaveToFile("sc.png");//Save screenshot
return 0;
}