Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Resizing a RenderTexture?  (Read 5789 times)

0 Members and 1 Guest are viewing this topic.

Sub

  • Full Member
  • ***
  • Posts: 159
    • View Profile
Resizing a RenderTexture?
« on: May 17, 2015, 08:41:01 pm »
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;
}

G.

  • Hero Member
  • *****
  • Posts: 1595
    • View Profile
Re: Resizing a RenderTexture?
« Reply #1 on: May 17, 2015, 08:50:16 pm »
Your sprite texture rect doesn't change when you call setTexture again, unless you set the 2nd parameter to true.

Sub

  • Full Member
  • ***
  • Posts: 159
    • View Profile
Re: Resizing a RenderTexture?
« Reply #2 on: May 17, 2015, 08:51:00 pm »
That makes a great deal of sense.  Thanks for the quick reply, I appreciate it  :D

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Resizing a RenderTexture?
« Reply #3 on: May 17, 2015, 08:53:12 pm »
Too late, might as well erase
Your sprite texture rect doesn't change when you call setTexture again, unless you set the 2nd parameter to true.
You beat me to it!
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0