Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty RenderTexture after recreating window #1625

Closed
JaagupAverin opened this issue Dec 5, 2019 · 1 comment · Fixed by #1630
Closed

Empty RenderTexture after recreating window #1625

JaagupAverin opened this issue Dec 5, 2019 · 1 comment · Fixed by #1630
Assignees
Projects
Milestone

Comments

@JaagupAverin
Copy link

JaagupAverin commented Dec 5, 2019

Subject of the issue

Recreating RenderWindow causes Texts in RenderTexture to disappear.

Your environment

Windows 10,
SFML 2.5.2
MSVC C++17

Steps to reproduce

Compile and run the following code. Notice the commented line.

#include <SFML/Graphics.hpp>
#include <assert.h>

const sf::Vector2f CENTER{ 250.f, 250.f };
const std::string FONT_PATH = "fira_medium.ttf";

int main()
{
    sf::RenderWindow window{ sf::VideoMode(500u, 500u), "bug" };

    sf::Font font;
    assert(font.loadFromFile(FONT_PATH));

    sf::RenderTexture texts_rt;
    texts_rt.create(300u, 300u);

    sf::Sprite texts_sprite;
    texts_sprite.setOrigin(sf::Vector2f(150.f, 150.f));
    texts_sprite.setPosition(CENTER);
    texts_sprite.setTexture(texts_rt.getTexture());

    std::vector<sf::Text> texts;
    auto draw_texts_to_texture = [&]()
    {
        texts_rt.clear(sf::Color::Red);
        for (auto& text : texts)
            texts_rt.draw(text);
        texts_rt.display();
    };

    auto append_text = [&](const std::string& str) 
    {
        sf::Text text;
        text.setString(str);
        text.setFillColor(sf::Color::White);
        text.setOutlineColor(sf::Color::Black);
        text.setOutlineThickness(2.f);
        text.setFont(font);
        text.setCharacterSize(16u);
        text.setPosition(sf::Vector2f(10.f, texts.size() * 24.f));
        texts.emplace_back(std::move(text));

        draw_texts_to_texture();
    };
    append_text("Text should always be visible.");
    append_text("Press TAB to recreate window.");

    while (window.isOpen())
    {
        for (sf::Event event; window.pollEvent(event);)
        {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Tab)
            {
                window.create(sf::VideoMode(500u, 500u), "bug");
                append_text("Recreated Window."); // If we comment this out, there is no problem!
            }
        }

        window.clear(sf::Color::Black);
        window.draw(texts_sprite);
        window.display();
    }
}

Expected behavior

Nothing to change.

Actual behavior

The texts disappear.

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Dec 5, 2019
@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Dec 5, 2019
@eXpl0it3r eXpl0it3r moved this from Discussion to WIP in SFML 2.6.0 Dec 5, 2019
binary1248 added a commit that referenced this issue Dec 8, 2019
…context has to be tracked. In the case a context is re-created, FBO RenderTextures would not trigger resetting of the OpenGL states if they were drawn to first since re-initialization of the RenderTarget only happens when a context owner such as a RenderWindow is re-created. Fixes #1625.
@binary1248
Copy link
Member

This should be fixed in #1630.

@eXpl0it3r eXpl0it3r moved this from WIP to Review & Testing in SFML 2.6.0 Dec 9, 2019
@eXpl0it3r eXpl0it3r moved this from Review & Testing to Ready in SFML 2.6.0 Jan 2, 2020
SFML 2.6.0 automation moved this from Ready to Done Jan 2, 2020
eXpl0it3r pushed a commit that referenced this issue Jan 2, 2020
…context has to be tracked. In the case a context is re-created, FBO RenderTextures would not trigger resetting of the OpenGL states if they were drawn to first since re-initialization of the RenderTarget only happens when a context owner such as a RenderWindow is re-created. Fixes #1625.
Baardi pushed a commit to Baardi/SFML that referenced this issue Jan 8, 2020
…context has to be tracked. In the case a context is re-created, FBO RenderTextures would not trigger resetting of the OpenGL states if they were drawn to first since re-initialization of the RenderTarget only happens when a context owner such as a RenderWindow is re-created. Fixes SFML#1625.
Unarelith pushed a commit to Unarelith/SFML that referenced this issue May 28, 2020
…context has to be tracked. In the case a context is re-created, FBO RenderTextures would not trigger resetting of the OpenGL states if they were drawn to first since re-initialization of the RenderTarget only happens when a context owner such as a RenderWindow is re-created. Fixes SFML#1625.
Unarelith pushed a commit to Unarelith/SFML that referenced this issue May 28, 2020
…context has to be tracked. In the case a context is re-created, FBO RenderTextures would not trigger resetting of the OpenGL states if they were drawn to first since re-initialization of the RenderTarget only happens when a context owner such as a RenderWindow is re-created. Fixes SFML#1625.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.6.0
  
Done
3 participants