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

Author Topic: how to use RenderTexture properly (off-screen drawing) ?  (Read 3033 times)

0 Members and 1 Guest are viewing this topic.

Demir

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
how to use RenderTexture properly (off-screen drawing) ?
« on: February 17, 2014, 10:46:03 am »
Hello,

I'm trying to use off-screen drawing (in tutorial section "Drawing 2D stuff")

if i don't use set origin and scale it doesn't display properly.

What am I doing wrong?

   
sprite.setOrigin(0, 400);
sprite.scale(1, -1);
 


#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 400), "Render Texture");

    sf::RenderTexture rt;
    sf::Sprite sprite;

    rt.create(300, 400);
    //sprite.setOrigin(0, 400);
    //sprite.scale(1, -1);

    sf::RectangleShape rect;
    rect.setPosition(10, 20);
    rect.setSize(sf::Vector2f(50, 100));
    rect.setFillColor(sf::Color(0, 255, 0));
    rt.draw(rect);

    sprite.setTexture(rt.getTexture());
    sprite.setPosition(0, 0);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear(sf::Color::Black);
        window.draw(sprite);
        window.display();
    }

    return 0;
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: how to use RenderTexture properly (off-screen drawing) ?
« Reply #1 on: February 17, 2014, 10:51:55 am »
Please read the tutorial and/or documentation carefully...
Laurent Gomila - SFML developer

Demir

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: how to use RenderTexture properly (off-screen drawing) ?
« Reply #2 on: February 17, 2014, 11:16:25 am »
Thank you for the generic answer  :)

and I am sorry for not reading carefully...

I missed to call RenderTexture::display().
That's my fault.