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

viewport support #72

Open
vprimachenko opened this issue Jan 2, 2019 · 19 comments
Open

viewport support #72

vprimachenko opened this issue Jan 2, 2019 · 19 comments

Comments

@vprimachenko
Copy link

consider adding support for the upcoming viewports feature of ImGui

@eliasdaler
Copy link
Contributor

Sure! I knew about this for a while, but I didn't want to work on it, because it's not in a release yet, so I'd have to constantly keep up to date and fix every breaking change, which is a bit difficult.

If you want, I can try to make it work in the state that viewports are now in ImGui in experimental branch, but if you can wait until it's in one of ImGui's releases + some additional time it will take me to implement (PRs are welcome, if you really need it :D), I'l try to implement it later.

@gotocoffee1
Copy link

I tried that a few weeks ago and it wasn't that difficult. The biggest problem was to get the position of the render area relative to the desktop (main window only) without the window decoration.

@eric556
Copy link

eric556 commented Jun 21, 2019

@gotocoffee1 Do you have the code publicly available? I'd be interested in using this feature

@gotocoffee1
Copy link

@eric556 Not right now but I will look into this again and maybe do a pull request.

@gotocoffee1
Copy link

So I looked into the sample ports again and it seems that the platform has to be able to handle multiple monitors (right @ocornut ?), which is not supported by SFML.

@ocornut
Copy link

ocornut commented Jul 7, 2019

You need to be able to create multiple windows and share the graphics context.
Multiple monitor support is only a product of that.
If sfml doesn’t naturally support that you could perfectly use a separate backend for the secondary windows.

@FelipeCarlin
Copy link

Hi, does anyone have an implementation of this publicly available?

@SebastianMilosz
Copy link

In my project I'm using imgui from docking branch with sfml.
Docking functionality works, but i'm not able to create new windows. So im also waiting for this feature within imgui-SFML :-)

@CosminPerRam
Copy link

Something new about implementing the viewports?

@eliasdaler
Copy link
Contributor

I'm still not sure if I need to do anything on ImGui-SFML's side since you can have multiple ImGui contexts now and ImGui-SFML supports it.

@CosminPerRam
Copy link

I tried but it doesnt work, thats why i dropped a comment here, can you give it a go?

@eliasdaler
Copy link
Contributor

Can you please describe what doesn't work?
I don't have the time to try it out soon myself, unfortunately.

@CosminPerRam
Copy link

CosminPerRam commented Jun 5, 2022

Sorry for not leaving an example straight up, here it is:

So I'm just taking the simple example from here and modifying it for multi viewports (as said here (at How can I enable Multi-viewports ?)), here is the resulting code:

#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h

#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads

#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>
#include <iostream>

int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);
    ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; //added this! ---

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    sf::Clock deltaClock;
    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());

        ImGui::ShowDemoWindow();

        ImGui::Begin("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);

        std::cout << (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) << std::endl;

        if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) //added this! ---
        {
            ImGui::UpdatePlatformWindows();
            ImGui::RenderPlatformWindowsDefault();
        }

        window.display();
    }

    ImGui::SFML::Shutdown();

    return 0;
}

And i would be able to get the imgui windows outside of the main sfml window but i cant.
image

Also, ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable returns 0 and I see that the comment for ImGuiConfigFlags_ViewportsEnable says:
image

Edit: I added those flags in imgui-SFML.cpp and now i get:
image

@eliasdaler
Copy link
Contributor

eliasdaler commented Jun 5, 2022

Yeah, now I see that it requires some additional coding which seems not very trivial...
https://github.com/ocornut/imgui/blob/docking/backends/imgui_impl_sdl.cpp#L341
https://github.com/ocornut/imgui/blob/docking/backends/imgui_impl_sdl.cpp#L697

At best I could be able to start researching this next month... so if someone has more time and wants to implement this, I'd be more than happy to accept the PR. :)

@CosminPerRam
Copy link

CosminPerRam commented Jun 5, 2022

I'm no way this advanced, but I'll give it a go, thanks for reaching out for this.

@ignotion
Copy link

ignotion commented Dec 9, 2022

@eliasdaler were you able to start it?

@eliasdaler
Copy link
Contributor

@ignotion, there's this PR: #213
However, it needs testing (I wasn't able to do it, unfortunately)

@PanAMD
Copy link

PanAMD commented Nov 7, 2023

Hey is this feature going to be released?, I would be a huge addition to the library, supporting viewports.

@anthony-sv
Copy link

5 years and nothing... Crazy.

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

No branches or pull requests