0

我正在尝试设置 ImGui 来制作一些应用程序,但是我无法让它工作。我从 GitHub,https://github.com/ocornut/imgui安装了.h和文件,并按照说明允许项目编译,它确实如此。但是在 Windows 和 Linux 上(我都试过了),它会吐出一个运行时错误,(停止响应 Windows,分段错误(核心转储)Linux)。这是发布的示例代码,.cpp

#include "imgui.h"

int main()
{


    // Create a window called "My First Tool", with a menu bar.
    ImGui::Begin("My First Tool", &my_tool_active, ImGuiWindowFlags_MenuBar);
    if (ImGui::BeginMenuBar())
    {
        if (ImGui::BeginMenu("File"))
        {
            if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */ }
            if (ImGui::MenuItem("Save", "Ctrl+S"))   { /* Do stuff */ }
            if (ImGui::MenuItem("Close", "Ctrl+W"))  { my_tool_active = false; }
            ImGui::EndMenu();
        }
        ImGui::EndMenuBar();
    }

    // Edit a color (stored as ~4 floats)
    ImGui::ColorEdit4("Color", my_color);

    // Plot some values
    const float my_values[] = { 0.2f, 0.1f, 1.0f, 0.5f, 0.9f, 2.2f };
    ImGui::PlotLines("Frame Times", my_values, IM_ARRAYSIZE(my_values));

    // Display contents in a scrolling region
    ImGui::TextColored(ImVec4(1,1,0,1), "Important Stuff");
    ImGui::BeginChild("Scrolling");
    for (int n = 0; n < 50; n++)
        ImGui::Text("%04d: Some text", n);
    ImGui::EndChild();
    ImGui::End();



    return 0;
}

my_tool_active现在这段代码由于and无法编译my_color,所以我在代码之前添加了这两行ImGui::Begin()

bool my_tool_active = true;
float my_color[4] = {0.5, 0.5, 0.5, 1};

所以现在当我编译和运行时,它会ImGui::Begin()在那个阶段崩溃。我在一个小得多的示例中尝试过它,它只是ImGui::Begin()andImGui::End()并在其周围放置了 print 语句,它表明它从未完成执行Begin().

4

1 回答 1

0

Imgui 不提供图形后端,也不创建窗口或图形 API 上下文。您必须自己提供(使用 OpenGL/DirectX/Vulkan ecc...)或使用为您创建的库(SDL/glfw ecc...)。

请参阅示例目录以获取更完整的示例。

这个使用 sdl+openGl。 https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl3/main.cpp

于 2020-12-28T02:34:09.740 回答