SFML/imgui-sfml

Imgui Images, missing attributes

Closed this issue · 5 comments

in the sfml backend for imgui there is no option to set the uv coordinates of the top left and bottom right corners

image

where in imgui

IMGUI_API void Image(
ImTextureID user_texture_id,
const ImVec2& image_size,
const ImVec2& uv0 = ImVec2(0, 0),
const ImVec2& uv1 = ImVec2(1, 1),
const ImVec4& tint_col = ImVec4(1, 1, 1, 1),
const ImVec4& border_col = ImVec4(0, 0, 0, 0)
);

this is a problem because the defaults are flipped compared to sfml, and so this mage the rendered image flipped with no way to be un-flipped ..

image

would it be possible to add the uv coordinated options to the imgui-sfml backend overloads please ?

Has this been solved already? I was looking into it but I can't really replicate the issue, plus there's this lines on the Image() implementation that seem to be there to fix this specific issue:

imagen

If you still have this problem I'll like to see your code, I just replicated it by doing the following and it didn't flip the image:

    sf::Texture const texture("my_texture.png");
    sf::Sprite sprite(texture);
    while (window.isOpen())
    {
        while (const auto event = window.pollEvent())
        {
            ImGui::SFML::ProcessEvent(window, *event);

            if (event->is<sf::Event::Closed>())
            {
                window.close();
            }
        }

        ImGui::SFML::Update(window, deltaClock.restart());

        ImGui::Begin("Hello, world!");
        // Image within a window, not flipped
        ImGui::Image(texture);
        ImGui::End();

        window.clear();
        // Background image, also not fliped
        window.draw(sprite);
        ImGui::SFML::Render(window);
        window.display();
    }

Hey !
I should have been more clear sorry, the problem does not occur with textures but with renderTextures (used as a framebuffer in my project) :

Here is a simple demo showcasing the flipped render texture :

sf::RenderTexture frameBuffer;
    if (!frameBuffer.create(800, 600)) {
        return -1;
    }

    sf::Texture texture;
    if (!texture.loadFromFile("texture.png")) {
        return -1;
    }

    sf::Sprite sprite(texture);

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

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

        ImGui::SFML::Update(window, deltaClock.restart());

        frameBuffer.clear(sf::Color::White);
        frameBuffer.draw(sprite);
        frameBuffer.display();

        sf::Sprite frameBufferSprite(frameBuffer.getTexture());

        ImGui::Begin("Frame Buffer View");
        ImGui::Image(frameBuffer.getTexture(), sf::Vector2f(400, 300));
        ImGui::End();

        ImGui::Begin("Original Texture View");
        ImGui::Image(texture, sf::Vector2f(400, 300));
        ImGui::End();

        window.clear(sf::Color::White);
        window.draw(frameBufferSprite);
        ImGui::SFML::Render(window);
        window.display();
    

By calling this:

ImGui::Image(frameBuffer.getTexture(), sf::Vector2f(400, 300));

you're calling a wrong overload. Instead, it should be called like this:

ImGui::Image(frameBuffer, sf::Vector2f(400, 300));

RenderTextures are stored flipped in VRAM, there's nothing we can do to detect that if you just pass an sf::Texture

@ChrisThrasher - we discussed this in some previous issue, but this thing can be solved better if Texture::m_pixelsFlipped ever gets a public getter.

@ChrisThrasher - we discussed this in some previous issue, but this thing can be solved better if Texture::m_pixelsFlipped ever gets a public getter.

SFML/SFML#1770 (comment)

I'll see if there is any desire amongst the team to make this happen. It's mostly up to Binary and Exploiter. I'm not opposed to it.

Thank you for the help !