我正在使用带有GLFW和GLEW的openGL。我正在使用着色器渲染所有内容,但似乎深度缓冲区不起作用。我用于3D渲染的着色器是:
顶点着色器
#version 410\n
layout(location = 0) in vec3 vertex_position;
layout(location = 1) in vec2 vt
uniform mat4 view, proj, model;
out vec2 texture_coordinates;
void main() {
texture_coordinates = vt;
gl_Position = proj * view * model* vec4(vertex_position, 1.0);
};
片段着色器
#version 410\n
in vec2 texture_coordinates;
uniform sampler2D basic_texture;
out vec4 frag_colour;
void main() {
vec4 texel = texture(basic_texture, vec2(texture_coordinates.x, 1 - texture_coordinates.y));
frag_colour = texel;
};
而且我还启用了深度缓冲和剔除面
glEnable(GL_DEPTH_BUFFER);
glDepthFunc(GL_NEVER);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
这是它的样子:
您没有启用深度测试。更改glEnable(GL_DEPTH_BUFFER);
为glEnable(GL_DEPTH_TEST);
可能使用检测到此错误glGetError()
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句