首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有显示ImGui

没有显示ImGui
EN

Stack Overflow用户
提问于 2017-07-21 06:31:05
回答 1查看 4K关注 0票数 0

我正试图在Windows上制作一个OpenGL程序。由于主exe文件越来越大,我决定将其拆分为DLL。我的问题就是这样开始的。

对于ImGui函数,我创建了一个类。下面是我的类的呈现()函数:

代码语言:javascript
复制
cout << "render" << endl;
imgui_newFrame();
{
    ImGui::SetNextWindowSize(ImVec2(30, 30), ImGuiSetCond_FirstUseEver);
    ImGui::Begin("Test", &show_another_window);
    ImGui::Button("Test Window");
    ImGui::End();
}
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
ImGui::Render();

在类中调用render()函数之前,我在类中的另一个函数中启动ImGui,如下所示:

代码语言:javascript
复制
if (!imgui_init(glfw_window)) {
    return false;
}

这是我的主要的glfw循环:

代码语言:javascript
复制
while (!glfwWindowShouldClose(window)) {
    glClear(GL_COLOR_BUFFER_BIT);
    glfwPollEvents();
    MyMyGuiClass.render(); //here i ask my class to render imgui
    glfwSwapBuffers(window);
}

使用这段代码,我能够使ImGui清晰的窗口颜色(glClearColor函数工作,我的控制台打印“呈现”)

但它没有显示任何其他东西。

顺便说一句,这是命令在我运行时工作得很好。

代码语言:javascript
复制
while (!glfwWindowShouldClose(window)) {
    glClear(GL_COLOR_BUFFER_BIT);
    glfwPollEvents();
    imgui_newFrame();
    {
        ImGui::SetNextWindowSize(ImVec2(30, 30), ImGuiSetCond_FirstUseEver);
        ImGui::Begin("", &show_another_window);
        ImGui::Button("Test Window");
        ImGui::End();
    }
    glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
    ImGui::Render();
    glfwSwapBuffers(window);
}

我使用的是VS2017,我的编译器在编译它时不会显示任何警告或错误。此外,我试图使我的类函数是静态的,但是我什么也没有得到。

因此,简单地说,当从类内部调用ImGui时,它不能呈现吗?

EN

回答 1

Stack Overflow用户

发布于 2017-07-21 09:13:09

您遇到的问题是,ImGui维护一个全局状态,并且必须将该状态保存在某个地方。ImGui将其保存在一个模块-本地全局符号中。

请注意这里的“模块-本地”!这意味着每个DLL (以及主EXE)都得到它自己的状态副本。因此,在DLL "A“(或EXE "1”)中使用ImGui来处理它自己的ImGui状态实例。

有一个解决方案,通过让这个讨厌的ImGui全局状态跨DLL共享。在这里,https://msdn.microsoft.com/en-us/library/h90dkhs0(v=vs.90).aspx描述了如何在DLL之间共享数据--关于ImGui本身的详细信息。它主要归结为正在使用的ImGuiContext。就目前而言,这是一个模块本地全局变量,但ImGui开发部门计划使其在每次调用中显式化,并最终对用户进行管理。

来自ImGui代码的注释:

代码语言:javascript
复制
// Default context storage + current context pointer.  Implicitely used by all
// ImGui functions. Always assumed to be != NULL. Change to a different context
// by calling ImGui::SetCurrentContext() ImGui is currently not thread-safe
// because of this variable. If you want thread-safety to allow N threads to
// access N different contexts, you might work around it by: - Having multiple
// instances of the ImGui code compiled inside different namespace
// (easiest/safest, if you have a finite number of contexts) - or: Changing
// this variable to be TLS. You may #define GImGui in imconfig.h for further
// custom hackery. Future development aim to make this context pointer explicit
// to all calls. Also read https://github.com/ocornut/imgui/issues/586
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45230553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档