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

Author Topic: sf::RenderTexture without 'display' call.  (Read 400 times)

0 Members and 1 Guest are viewing this topic.

achpile

  • Full Member
  • ***
  • Posts: 221
    • View Profile
    • Achpile's homepage
    • Email
sf::RenderTexture without 'display' call.
« on: October 30, 2017, 02:21:56 pm »
Don't know if it's a bug, but if I don't call 'display' function - render texture draws upside down.

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

int main() {
        sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
        sf::Event event;
        sf::Font font;
        sf::Text text;
        sf::RectangleShape shape;
        sf::Sprite spr;
        sf::RenderTexture tex;

        font.loadFromFile("font.ttf");

        text.setFont(font);
        text.setString("HELLO");
        text.setCharacterSize(200);
        text.setFillColor(sf::Color::Black);

        shape.setSize(sf::Vector2f(100,100));
        shape.setPosition(100, 300);
        shape.setFillColor(sf::Color::Black);

        tex.create(800,600);
        tex.setActive(true);

        tex.clear(sf::Color::White);
        tex.draw(text);
        tex.draw(shape);
        //tex.display();

        spr.setTexture(tex.getTexture());

        while (window.isOpen()) {
                while (window.pollEvent(event)) if (event.type == sf::Event::Closed) window.close();

                window.clear(sf::Color::White);
                window.draw(spr);
                window.display();
        }

        return 0;
}
 

1.png - with 'display' call
2.png - without

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9318
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture without 'display' call.
« Reply #1 on: October 30, 2017, 02:28:29 pm »
You have to call display, it's not optional, so anything that you get when not calling display is more or less "undefined behavior".
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

achpile

  • Full Member
  • ***
  • Posts: 221
    • View Profile
    • Achpile's homepage
    • Email
Re: sf::RenderTexture without 'display' call.
« Reply #2 on: October 30, 2017, 02:30:22 pm »
You have to call display, it's not optional, so anything that you get when not calling display is more or less "undefined behavior".

oh, okay :) thanks for explanation  ;) i just spent 15 minutes to figure out, why my text was upside down  :D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9318
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture without 'display' call.
« Reply #3 on: October 30, 2017, 02:47:16 pm »
Yes, it's a common "problem" when not calling display() on a render texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/