ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
60.62k stars 10.23k forks source link

ImGui Windows not showing #4287

Closed androbytes closed 3 years ago

androbytes commented 3 years ago

Sorry if this a stupid question, but, how does DockSpace work? I have no idea what a ImGuiID is but I'd just like to make a opengl window a dockspace, Thanks!

ocornut commented 3 years ago

There are examples in the demo and copious amount of comments.

androbytes commented 3 years ago

Yes, I know, but I still don't understand it what so ever.

PathogenDavid commented 3 years ago

It sounds like DockSpaceOverViewport is what you're looking for. IE:

ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());

If you want more control than it provides, you have to use ImGui::DockSpace directly. All that matters is the ID is unique, you can make an ImGuiID from a string using ImGui::GetID. IDs are further explained by this FAQ.

AidanSun05 commented 3 years ago

You said that you didn't understand the demo code for the DockSpace. It's true that there's a lot going on inside the demo function, so here's a gist containing some more clarifying comments. This should help you to understand the functionality and usage more.

https://gist.github.com/AidanSun05/b342f1bf023e931695473e343569759c

androbytes commented 3 years ago

Thanks @PathogenDavid

androbytes commented 3 years ago

Now what happens is I get no ImGui windows... Odd

PathogenDavid commented 3 years ago

Not sure what to tell you besides that shouldn't happen. It'd help if you could share some of your code.

DockSpaceOverViewport should be called on its own (IE: not inside of a Begin..End block) and as early as possible (ideally right after ImGui::NewFrame.)

Are you on the latest version of the docking branch?

androbytes commented 3 years ago

Yes.

androbytes commented 3 years ago
        ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();

    // Dockspace
    ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());

    /*Rendering*/
    glClear(GL_COLOR_BUFFER_BIT);

    //ImGui Rendering
    {

        //Menubar
        Core::RenderMenuBar();

        //Viewport

        //Console
        ImGui::Begin("Console");

        static ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
        if (ImGui::BeginTable("", 2, flags))
        {
            ImGui::TableSetupScrollFreeze(0, 1);
            ImGui::TableSetupColumn("Information", ImGuiTableColumnFlags_None);
            ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_None);
            ImGui::TableHeadersRow();
            for (int i = 0; i < Core::consoleText.size(); i++) {
                for (int ii = 0; ii < Core::type.size(); ii++) {
                    // Info List(IL)
                    auto l_front = Core::consoleText.begin();
                    std::advance(l_front, i);
                    std::string string = *l_front;
                    // Console Type List(CTL)
                    auto l_frontt = Core::type.begin();
                    std::advance(l_frontt, i);
                    Core::ConsoleType ctypeo = *l_frontt;
                    std::string ctype;
                    switch (ctypeo) {
                        case Core::ConsoleType::Message:
                            ctype = "Message";
                            break;
                        case Core::ConsoleType::Warning:
                            ctype = "Warning";
                            break;
                        case Core::ConsoleType::Error:
                            ctype = "Error";
                            break;
                    }
                    ImGui::TableNextColumn();
                    ImGui::Text(string.c_str());
                    ImGui::TableNextColumn();
                    ImGui::Text(ctype.c_str());
                }
            }
        }

        ImGui::EndTable();
        ImGui::End();
    }

    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

    if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
    {
        GLFWwindow* backup_current_context = glfwGetCurrentContext();
        ImGui::UpdatePlatformWindows();
        ImGui::RenderPlatformWindowsDefault();
        glfwMakeContextCurrent(backup_current_context);
    }

    /*End of rendering*/

    glfwSwapBuffers(window);

    glfwPollEvents();
AidanSun05 commented 3 years ago

You might have to provide more details - what's inside of Core::RenderMenuBar()? Are Core::consoleText and Core::type strings, containers (e.g. vector, deque), or something else like your own class/struct?

In the meantime, there are some minor errors in your main loop's structure. It's a common convention to call glfwPollEvents() as the very first thing (you have it as the very last). glClear(GL_COLOR_BUFFER_BIT) should be near the end, along with other OpenGL function calls which you have missed.

// Main loop
while (!glfwWindowShouldClose(window)) {
    // Handle the creation of a new frame
    glfwPollEvents(); // MOVED THIS
    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();

    // Dockspace
    ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());

    //
    // [Put your window rendering code here]
    //

    // Handle the rendering of the main and detached viewports
    ImGui::Render();
    int w, h;                                 // ADDED THIS
    glfwGetFramebufferSize(window, &w, &h);   // ADDED THIS
    glViewport(0, 0, w, h);                   // ADDED THIS
    glClearColor(0.45f, 0.55f, 0.60f, 1.00f); // ADDED THIS
    glClear(GL_COLOR_BUFFER_BIT);             // MOVED THIS
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

    if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
        GLFWwindow* backup_current_context = glfwGetCurrentContext();
        ImGui::UpdatePlatformWindows();
        ImGui::RenderPlatformWindowsDefault();
        glfwMakeContextCurrent(backup_current_context);
    }

    glfwSwapBuffers(window);
}
androbytes commented 3 years ago

Okay, Core::consoleText is text to show onto the console and Core::type is the type of message it is. Core::RenderMenuBar just has simple code to render a menu bar:

     if (ImGui::BeginMainMenuBar()) {
        if (ImGui::BeginMenu("File")) {
            if (ImGui::MenuItem("Save")) {

            }
            if (ImGui::MenuItem("Open")) {

            }
            if (ImGui::MenuItem("Close")) {

            }
            ImGui::EndMenu();
        }

        if (ImGui::BeginMenu("Edit")) {
            //if(ImGui::MenuItem("")) {}
            ImGui::EndMenu();
        }

        ImGui::EndMainMenuBar();
    }
androbytes commented 3 years ago

Im confused. I tried tagging out the dockspaceoverviewport and there are still no windows

AidanSun05 commented 3 years ago

Based on your repro and my main loop template, I made a quick test program (I can share it if you'd like).

Here's the result:

image

Is this the expected behavior?

androbytes commented 3 years ago

Yes

androbytes commented 3 years ago

Also, if you can, add info on what you changed or added or moved. Thanks

AidanSun05 commented 3 years ago

So I'm guessing it's something in your main loop, not something regarding Dockspaces.

Here's the full code: https://gist.github.com/AidanSun05/1b9023db840dd3ce95ffd3af37e488db

The main loop starts on line 162.

androbytes commented 3 years ago

Hmm. Odd. I don't see much of a difference.

AidanSun05 commented 3 years ago

It's mostly just the start and end of the main loop:

(Lines 166-170)

// Handle the creation of a new frame
glfwPollEvents(); // MOVED THIS
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

(Lines 220-236)

// Handle the rendering of the main and detached viewports
ImGui::Render();
int w, h;                                 // ADDED THIS
glfwGetFramebufferSize(window, &w, &h);   // ADDED THIS
glViewport(0, 0, w, h);                   // ADDED THIS
glClearColor(0.45f, 0.55f, 0.60f, 1.00f); // ADDED THIS
glClear(GL_COLOR_BUFFER_BIT);             // MOVED THIS
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
    GLFWwindow* backup_current_context = glfwGetCurrentContext();
    ImGui::UpdatePlatformWindows();
    ImGui::RenderPlatformWindowsDefault();
    glfwMakeContextCurrent(backup_current_context);
}

glfwSwapBuffers(window);
androbytes commented 3 years ago

Yes, I have changed that, and still, nothing

AidanSun05 commented 3 years ago

Can you show a screenshot? In cases of unexpected behavior, this is almost always one of the best pieces of information you can provide (other than your code, of course).

androbytes commented 3 years ago

Screenshot of what, exactly?

AidanSun05 commented 3 years ago

Your Dear ImGui window (the whole thing). Like what I sent earlier.

androbytes commented 3 years ago

Okay, here:

Screenshot 2021-06-30 205119
androbytes commented 3 years ago

Nothing else. No windows, no nothing, just this glfw window. The only thing working is the menu bar. Not the windows

androbytes commented 3 years ago

Is this possibly a problem with ImGui? Or my code?

AidanSun05 commented 3 years ago

You copied my whole gist into your file and ran it, correct?

androbytes commented 3 years ago

I didn't copy the entire thing but I changed my code from what you wrote.

androbytes commented 3 years ago

As in I didn't copy the table code

androbytes commented 3 years ago

Worked perfectly before. But now, not for some odd reason

AidanSun05 commented 3 years ago

There are two main sections you need to copy in, they're highlighted in one of my above comments. Remember to not leave anything out:

https://github.com/ocornut/imgui/issues/4287#issuecomment-871680825

androbytes commented 3 years ago

Yes, I have made those changes. It did nothing.

AidanSun05 commented 3 years ago

Then it's probably not the code.

Did you update or change any of the following recently?

androbytes commented 3 years ago

Hm. I remember re-installing my driver adapter and also repairing visual studio. But that's it

AidanSun05 commented 3 years ago

Try to test your code on a different machine, this could just be a temporary issue.

Or, if you don't have another machine, you can reboot your computer, then try again.

androbytes commented 3 years ago

I don't have a different machine and I just restarted my pc and still doesn't work.

AidanSun05 commented 3 years ago

You said that it worked perfectly before, so there must be something that changed. It's most likely a program that auto-updated without you knowing.

If you're on Windows, you can go to Control Panel > Programs > Programs and Features to get a list of every installed program on your computer.

You should look for anything that has an install date that's very recent (within a week or two). In the screenshot below, my NVIDIA graphics driver was updated recently, so that's a possible candidate.

image

androbytes commented 3 years ago

I installed cosmos. If that could be a problem?

androbytes commented 3 years ago

And docker possibly

AidanSun05 commented 3 years ago

As long as it's not running in the background (you can check with Task Manager - Ctrl+Shift+Esc - under the heading "Background Processes") it should be okay.

androbytes commented 3 years ago

Well, docker is on as a background process so.

AidanSun05 commented 3 years ago

Is there anything that's gobbling up your system resources (Docker can potentially do so) or using a lot of power? If your CPU, GPU, or RAM is getting topped off, that may be hindering your code's rendering.

androbytes commented 3 years ago

Uh, no not really.

AidanSun05 commented 3 years ago

There's too many variables at play here.

Run my example test code (remember it's at https://gist.github.com/AidanSun05/1b9023db840dd3ce95ffd3af37e488db - paste in the whole thing, don't just edit the modified parts) and reply with what happens. Maybe you didn't copy something in correctly earlier?

androbytes commented 3 years ago

That didn't work

AidanSun05 commented 3 years ago

Does the example in the main repository work for you? (Download the docking branch ZIP, extract it, open imgui-docking/examples/imgui_examples.sln, then run the example_glfw_opengl3 project)

jrynkiew commented 3 years ago

Yeah, I deleted my message since it didn't make sense. I only realized after I posted :P

Wysłane z mojego BlackBerry — najbezpieczniejszego urządzenia mobilnego Od: @. Wysłano: 30 czerwca 2021 23:57 Do: @. Odp. do: @. DW: @.; @.*** Temat: Re: [ocornut/imgui] ImGui Windows not showing (#4287)

Hello @jrynkiewhttps://github.com/jrynkiew,

Dockspaces can be declared in a one-liner. If you do it like this, it will have no windows docked inside it. This is because the point of a dockspace is not to contain other windows, but to provide slots to dock windows into (user drags windows into the slots), if that makes any sense.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ocornut/imgui/issues/4287#issuecomment-871753665, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APA7H47QCQE5EXLD3ZG24JDTVOHNXANCNFSM47Q3POQQ.

ocornut commented 3 years ago

If the menu bar shows its not an external problem. OP very probably made a mistake somewhere in the ImGui using code or in their app structure but as we are only seeing incomplete blurbs of the code or confirmation that “yes I have copied your code correctly and it doesn’t work” its hard to guess what the mistake is.

Start by fullfilling the issue template and pasting the contents of the About box, then try to disable multi-viewport if enabled. That’s the only thing I could imagine could interfere if somehow you had a weird/broken backend, which again we don’t know anything about because you omitted those information from the issue template.

ocornut commented 3 years ago

@AnnoyingB instead of vaguely stating “that didn’t work” please be very explicit about what you did and the output. I am pretty convinced Aidan’s last blurb should work and you didn’t set it up correctly.

For what it is worth, the mistake may be even that your project/ide is setup wrongly. Some people spend hours not even building or running the right executable. It could be anything, but if you are not providing us enough precise details we can’t narrow things down.

Try to start from dear imgui stock examples (sln file in the repo) and confirm that it works.

androbytes commented 3 years ago

ShowDemoWindow works fine. But my code doesn't

androbytes commented 3 years ago

If I try running the glfw example, it shows errors that it can't find stuff.