I can't figure out how to resize a RenderTexture.
This is some test code I've tried. The desired result is a screen which is entirely green, but instead I'm left with a screen that's 1/4th green.
The code creates a render texture at half of the windows width and height, and then clears it red and draws the RenderTexture to the screen. It then calls create again with the full window width/height, and repeats the process but this time with the color green. Green does indeed get drawn, but the size remains half window width/height.
What am I doing wrong?
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode(200, 200), "SFML works!");
sf::RenderTexture RT;
//create half screen size
RT.create(100, 100);
RT.clear(sf::Color::Red);
RT.display();
sf::Sprite Sprite;
Sprite.setTexture(RT.getTexture());
Window.clear();
Window.draw(Sprite);
Window.display();
//Right now the screen is a red rectangle starting from the top left to the middle
//lets try to resize the render texture so that the entire screen is filled by it
RT.create(200, 200);
RT.clear(sf::Color::Green);
RT.display();
Sprite.setTexture(RT.getTexture());
//doesn't seem to have an effect though. The RenderTexture will clear green, but the
//rectangle will still only go from the topleft to the middle
while (Window.isOpen())
{
sf::Event event;
while (Window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
Window.close();
}
Window.clear();
Window.draw(Sprite);
Window.display();
}
return 0;
}
I've also tried to make it a bit more explicit by making the RenderTexture a pointer, and allocating it with new
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode(200, 200), "SFML works!");
sf::RenderTexture *RT = new sf::RenderTexture();
//create half screen size
RT->create(100, 100);
RT->clear(sf::Color::Red);
RT->display();
sf::Sprite Sprite;
Sprite.setTexture(RT->getTexture());
Window.clear();
Window.draw(Sprite);
Window.display();
//Right now the screen is a red rectangle starting from the top left to the middle
//lets try to resize the render texture so that the entire screen is filled by it
delete RT;
RT = new sf::RenderTexture();
RT->create(200, 200);
RT->clear(sf::Color::Green);
RT->display();
Sprite.setTexture(RT->getTexture());
//doesn't seem to have an effect though. The RenderTexture will clear green, but the
//rectangle will still only go from the topleft to the middle
while (Window.isOpen())
{
sf::Event event;
while (Window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
Window.close();
}
Window.clear();
Window.draw(Sprite);
Window.display();
}
return 0;
}