c++openglsfml

Rotate texture sfml and save output to file


I want to start out by saying I am a complete c++ novice. I do not know any of the vocabulary associated with it so if this question is trivial I apologies, as I do not now the correct terms or phrases to google the solution myself.

Currently playing around with this code I found on github to capture gameplay from my 3ds. https://github.com/Gotos/Cute3DSCapture/blob/master/main.cpp

I am trying to add the ability to rotate the image and save it to a png file.

from main.cpp around lines 267 I am trying to add the following functionality.

sprite.setTexture(texture);
sprite.rotate(90);
texture = sprite.getTexture();
texture.copyToImage().saveToFile("Something/Place/img.png");

Current texture and sprite are defined as the following.

sf::Texture texture;
sf::Sprite sprite;

When I try to build and run I get the followin

main.cpp:269:25: error: no viable overloaded '='
                texture = sprite.getTexture();
                ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~
/usr/local/include/SFML/Graphics/Texture.hpp:421:14: note: candidate function
      not viable: no known conversion from 'const sf::Texture *' to
      'const sf::Texture' for 1st argument; dereference the argument with *
    Texture& operator =(const Texture& right);

Any help would be greatly appreciated.


Solution

  • sf::Sprite is not a texture manipulator, which means that the texture returned by sf::Sprite::getTexture() will not be modified. That's why the Sprite's ctor takes a reference to a const texture instance.

    If you're solely interested in image manipulation, I'd recommend using something else than SFML as you might get better features/performance for specific operations. Probably something like imagemagick.

    With SFML, you can do it roughly like this:

    Look at the detailed description of sf::RenderTexture for an example of use.