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

Author Topic: sf::RenderTexture Flipped  (Read 4780 times)

0 Members and 1 Guest are viewing this topic.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
sf::RenderTexture Flipped
« on: February 11, 2013, 06:19:51 am »
Hello!
Raised two questions on the same topic

Here is the code
#include <SFML/Graphics.hpp>

int main()
{
    sf::VideoMode VMode(800, 600, 32);
    sf::RenderWindow Window(VMode, "SFML 2", sf::Style::Close);


    sf::RenderTexture texture;
    if (!texture.create(500, 500))
     return -1;

    sf::Text text;
    text.setString("TEST");
    text.setPosition(0.0f, 0.0f);
    text.setColor(sf::Color(255, 0, 0));

    sf::Texture texture_img;
    texture_img.loadFromFile("image.png");
    sf::Sprite sprite_image;
    sprite_image.setTexture(texture_img);

    while(Window.isOpen())
    {
        sf::Event Event;
        while(Window.pollEvent(Event))
        {
            switch(Event.type)
            {
                case sf::Event::Closed:
                    Window.close();
                    break;
                case sf::Event::KeyPressed:
                    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        Window.close();
                    break;
                default:
                    break;
            }
        }

        texture.clear(sf::Color::Blue);
        texture.draw(text);
        texture.draw(sprite_image);
//        texture.display();

        Window.clear(sf::Color(128, 128, 128));

        sf::Sprite sprite(texture.getTexture());
        Window.draw(sprite);
        Window.display();
    }
    return 0;
}

1. Why texture turns upside down, and what you can do

2. When the string / / texture.display (); longer displayed texture that I do not?


G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: sf::RenderTexture Flipped
« Reply #1 on: February 11, 2013, 07:11:08 am »
More information about the upside down RenderTexture.
Anyway, your RenderTexture has to call display after you draw something on it. The sf::RenderTexture documentation states that "Not calling it [display] may leave the texture in an undefined state", upside down for example.  :P

I don't understand question number 2.
« Last Edit: February 11, 2013, 07:13:50 am by G. »

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::RenderTexture Flipped
« Reply #2 on: February 11, 2013, 07:27:15 am »
Quote
I don't understand question number 2.
Uncomment this line if nothing is drawn

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::RenderTexture Flipped
« Reply #3 on: February 11, 2013, 07:42:30 am »
Looked at the forum here that I found.
        sf::Sprite sprite(texture.getTexture());
        sprite.setScale(1.0, -1.0);
        sprite.setPosition(0.0, 500.0);

But then the wrong position on the Y.
Is that correct?

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::RenderTexture Flipped
« Reply #4 on: February 11, 2013, 11:57:08 am »
Try to run on another computer, worked. What's the matter do not know, maybe in a video card.

Here is another way to work on both computers.
        Window.clear(sf::Color(128, 128, 128));
        sf::Texture tex(texture.getTexture());
        sf::Sprite sprite(tex);
        Window.draw(sprite);
        Window.display();
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10976
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture Flipped
« Reply #5 on: February 11, 2013, 12:02:33 pm »
Did you actually read what G. said? ???

More information about the upside down RenderTexture.
Anyway, your RenderTexture has to call display after you draw something on it.

And your second question is still kind of lost in translation or something like that... :-\
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/