0

我正在尝试添加 imgui 来调试场景,但无论我调用渲染的顺序如何,imgui 总是在后面渲染。如果单独完成,场景和 imgui 渲染效果很好(评论其他)。我尝试禁用深度测试,使用模板功能,每次 imgui 首先呈现。渲染循环是

void render() {
            bool show_demo_window = true;
            bool show_another_window = false;
            ImVec4 clear_color = ImVec4(0.1f, 0.1f, 0.1f, 1.0f);
            float m_time = glfwGetTime();
            while (!glfwWindowShouldClose(window)) 
                glfwGetFramebufferSize(window, &framebufferwidth, &framebufferheight);
                glViewport(0, 0, framebufferwidth, framebufferheight);

                glBindFramebuffer(GL_FRAMEBUFFER, 0);
                glBindVertexArray(0);
                glBindTexture(GL_TEXTURE_2D, 0);

                finalShader->Use();
                for (int i = 0; i < finTex.size(); i++) {
                    finTex[i]->bind();
                    std::string top = "texture" + std::to_string(i);
                    finalShader->setUniform1i(top.c_str(), finTex[i]->getTextureUnit());
                }
                window2D->updateProjMatrix(window);
                winCam->sendToShader(finalShader);

                window2D->updateModelMatrix();

                window2D->Draw();
                finalShader->unUse();


                // Rendering ImGui
                ImGuiIO& io = ImGui::GetIO();
               int framebufferwidth;
               int framebufferheight;
               glfwGetFramebufferSize(window, &framebufferwidth, &framebufferheight);
               io.DisplaySize = ImVec2(framebufferwidth, framebufferheight);
               float time = glfwGetTime();
               io.DeltaTime = 1 / 60.f;

               // Start the Dear ImGui frame
               ImGui_ImplOpenGL3_NewFrame();
               ImGui_ImplGlfw_NewFrame();
               ImGui::NewFrame();
                if (show_demo_window)
                    ImGui::ShowDemoWindow(&show_demo_window);
                ImGui::EndFrame();


                 ImGui::Render();


                preRender();
                postRender();
                glfwSwapBuffers(window);
                glfwPollEvents();
                glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
                glClear(GL_COLOR_BUFFER_BIT);
                ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

            }
            ImGui_ImplOpenGL3_Shutdown();
            ImGui_ImplGlfw_Shutdown();
            ImGui::DestroyContext();
        }

也用于初始化 ImGui,因为我使用 opengl 4.4 初始化了窗口核心

ImGui_ImplOpenGL3_Init("#version 440");

此代码也位于不同的名称空间中,并生成一个 dll 文件,然后将其链接。

编辑:我得到了错误,它实际上不是我在使用ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());之后glfwSwapBuffers(window);

4

1 回答 1

0

看起来

ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

是实际呈现 Imgui 界面的内容,但它发生在

glClear(GL_COLOR_BUFFER_BIT);

虽然它在实践中发生在循环结束时会发生什么

  1. 清除

  2. 绘制 ImGUI

  3. DrawRest

  4. 清除

ETC..

所以 imGui 将永远在后面。要修复它,请尝试放置

ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT)

看看是否可以解决它。

于 2020-08-04T20:52:58.043 回答