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

[Linux] Rendering a rendertexture to ImGui::Image #11

Closed
kongo555 opened this issue Oct 28, 2016 · 5 comments
Closed

[Linux] Rendering a rendertexture to ImGui::Image #11

kongo555 opened this issue Oct 28, 2016 · 5 comments

Comments

@kongo555
Copy link

kongo555 commented Oct 28, 2016

Hello!
I have simillar problem to #8 and #10 but window.pushGLStates() and window.popGLStates() doesn't help. I'm rendering my scene to texture and then try to display it in imgui. It start to bug on renderTexture.display() method. I call it before ImGui::Render()

    renderTexture.clear();
    map->render(renderTexture);
    simulation->render(renderTexture, delta);
    renderTexture.display();

    ImGui::SFML::Update(elapsed);
    window->clear();
    gui->test();
    gui->render(sprite);
    ImGui::Render();

In test() and render(sprite) i call just imgui functions.
I'm using 2.4 sfml version.

Thanks in advance for help :)

EDIT:
It turns out that i don't have to use renderTexture.display() and then everything is fine.

@eliasdaler
Copy link
Contributor

Hmm, actually you have to use renderTexture.display()! Can you please find the minimal code which reproduces the problem? It will help me solve potentially undiscovered bugs.

Btw, I've tried doing the same thing as you, didn't have any problems.

@kongo555
Copy link
Author

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "");
    window.setVerticalSyncEnabled(true);
    ImGui::SFML::Init(window);

    bool show = true;

    sf::RenderTexture renderTexture;
    sf::Sprite sprite;

    if (!renderTexture.create(32, 32))
    {
        std::cout << "error renderTexture\n";
        // error...
    }
    sprite =  sf::Sprite(renderTexture.getTexture());
    sf::RectangleShape tileTexture(sf::Vector2f(32, 32));
    tileTexture.setFillColor(sf::Color::White);
    tileTexture.setPosition(0, 0);
    renderTexture.draw(tileTexture);
    renderTexture.display();

    sf::Clock deltaClock;
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            ImGui::SFML::ProcessEvent(event);

            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

        ImGui::SFML::Update(deltaClock.restart());
        ShowText(show);
        ShowImage(show, sprite);

        window.clear();
        ImGui::Render();

        window.display();
    }

    ImGui::SFML::Shutdown();
}

static void ShowText(bool& p_open)
{
    ImGui::SetNextWindowPos(ImVec2(10,10));
    if (!ImGui::Begin("Example: Text", &p_open))
    {
        ImGui::End();
        return;
    }
    ImGui::Text("Simple overlay\non the top-left side of the screen.");
    ImGui::Separator();
    ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
    ImGui::End();
}

static void ShowImage(bool& p_open, sf::Sprite sprite)
{
    ImGui::SetNextWindowPos(ImVec2(100,100));
    if (!ImGui::Begin("Example: Image", &p_open))
    {
        ImGui::End();
        return;
    }
    ImGui::Image(sprite);
    ImGui::End();
}

When i comment renderTexture.display(); everything works, without it i have buged window.

@eliasdaler
Copy link
Contributor

Calling display is needed here. And indeed, calling it there causes some problems.
It looks like this commit solves the issue. Can you try it out?

@kongo555
Copy link
Author

kongo555 commented Nov 2, 2016

Everything is fine now :)

@eliasdaler
Copy link
Contributor

eliasdaler commented Nov 2, 2016

Awesome!
I've also managed to remove reset/push/popGLStates calls in the latest version. Please try it out, and see if it works fine for you as well. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants