C# 未完全绘制和消失的面

C# 未完全绘制和消失的面,c#,opengl,glsl,shader,opentk,C#,Opengl,Glsl,Shader,Opentk,我正在尝试学习opengl,当我使用深度测试时,脸慢慢消失了,我不知道发生了什么,我在网上找不到任何东西 图纸代码: GLHelper.Clear(); GL.Enable(EnableCap.DepthTest); shader.Use(); shader.SetMatrix("projection", Matrix4.CreatePerspectiveFieldOfView(MathHelp

我正在尝试学习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;
}
启用时,必须清除颜色缓冲区旁边的深度缓冲区

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

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

是否清除深度缓冲区
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)
rabbi76哦,我想不是GLHelper.Clear被设置为GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.ColorBufferBit)lol