面孔未完全绘制和消失

faces not fully drawing and disappearing

我正在尝试学习 opengl,当我使用深度测试时,面孔慢慢消失我不确定发生了什么,我在网上找不到任何东西

绘图代码:

            GLHelper.Clear();
            GL.Enable(EnableCap.DepthTest);

            shader.Use();

            shader.SetMatrix("projection", Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver2, (float)Width / (float)Height, 0.01f, 1000.0f));
            shader.SetMatrix("view", Matrix4.LookAt(new Vector3(0,0,10),new Vector3(),Vector3.UnitY));
            shader.SetMatrix("transform",Matrix4.CreateRotationY((float)time));
            mesh.Draw();

            SwapBuffers();

mesh.draw:

            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBO);
            GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

            GL.DisableVertexAttribArray(1);
            GL.DisableVertexAttribArray(2);

着色器代码:

#version 440 core

layout (location = 0) in vec3 position;
layout(location = 1) in vec4 color;
uniform  mat4 transform;
uniform mat4 projection;
uniform mat4 view;

out vec4 fragcolor;

void main(void)
{
    gl_Position = projection * view * transform * vec4(position,1.0);

 //temp
 fragcolor = color;
}

启用Depth Test后,您必须清除颜色缓冲区旁边的深度缓冲区。

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

由于片段的深度值是根据缓冲区中的相应深度值进行测试的,因此必须在帧开始时清除深度缓冲区。