I am trying to render a 3d pyramid inside a frame buffer to display it in ImGui window. But the depth testing fails and I get this:
Here's what I have:
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();
}
Note: I got AppImguiAddImage() and Clear() originally from: https://gamedev.stackexchange.com/questions/150214/render-in-a-imgui-window
I have tried different combinations of color clear and depth clear for the two Clear() funtions in the while loop to get the same result.
What is going wrong?