Stretch sf :: Sprite all over the window
First, basic use of sprites from the tutorial.
Taken from my own answer to Resizing in SFML 2.0 , which by the way is the first Google result when searching for "sfml sprite fill the screen".
First, here you can scale the image to the current RenderWindow size.
// assuming the given dimension // change this dynamically with the myRenderWindow->getView().getSize() sf::Vector2f targetSize(900.0f, 1200.0f); yourSprite.setScale( targetSize.x / yourSprite.getLocalBounds().width, targetSize.y / yourSprite.getLocalBounds().height);
Remember that this can stretch your image if the aspect ratio is not supported. You might want to add some code to customize the solution for your case.
Then, if you want to stretch the RenderWindow to fill the entire screen, may I suggest you use full screen mode?
Here's a snippet of how it's done:
// add the flag to the other ones mStyleFlag = sf::Style::Default | sf::Style::Fullscreen; // get the video mode (which tells you the size and BPP information of the current display std::vector<sf::VideoMode> VModes = sf::VideoMode::getFullscreenModes(); // then create (or automatically recreate) the RenderWindow mMainWindow.create(VModes.at(0), "My window title", mStyleFlag);
If you're looking for a background, the most elegant way to do this is probably just to define sf :: VertexArray, which will render a square that fills your window using the correct texture coordinates.
This was taken from the second google result: What happened to sprite :: setSize in SFML2?
source to share