【发布时间】:2022-10-22 11:41:20
【问题描述】:
我正在尝试在帧缓冲区内渲染 3d 金字塔以在 ImGui 窗口中显示它。但是深度测试失败了,我得到了这个:
这是我所拥有的:
glEnable(GL_DEPTH_TEST);
while (!glfwWindowShouldClose(mainwin))
{
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
fbo.bind();//framebufferobject bind
glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Render here */
defaultshader.Activate();
// Handles camera inputs
camera1.Inputs(mainwin);
// Updates and exports the camera matrix to the Vertex Shader
camera1.Matrix(45.0f, 0.1f, 100.0f, defaultshader, "camMatrix");
tex1.Bind();
VAO1.Bind();
// Draw primitives, number of indices, datatype of indices, index of indices
glDrawElements(GL_TRIANGLES, sizeof(indices) / sizeof(int), GL_UNSIGNED_INT, 0);
//---------------------------------------------------------------------------------------------------------------------------
fbo.unbind();
ImGui::Begin("Viewport");
AppImguiAddImage(fbtex.FBtexID);//adds image to imgui drawlist
ImGui::End();
AppImguiFrameEnd();
/* Swap front and back buffers */
glfwSwapBuffers(mainwin);
/* Poll for and process events */
glfwPollEvents();
}
笔记: 我得到 AppImguiAddImage() 和 Clear() 最初来自: https://gamedev.stackexchange.com/questions/150214/render-in-a-imgui-window
我已经为 while 循环中的两个 Clear() 函数尝试了颜色清除和深度清除的不同组合,以获得相同的结果。
出了什么问题?
【问题讨论】:
-
@JesperJuhl 你的评论有什么意义?显然,OP 说深度测试在 OP 的代码中不起作用。
-
您的 FBO 是否有深度缓冲附件?
-
@YakovGalka 不,我认为深度和模板缓冲区只能附加到 RBO。我找不到有关如何将深度缓冲区附加到帧缓冲区的资源。您能否提供一些链接或示例行?
-
@SubhamSwostikPradhan,您没有将任何东西附加到 RBO;当您将 RBO 附加到 FBO 时,它们是纹理的替代品。