【发布时间】:2016-11-03 20:08:14
【问题描述】:
我将 openGL 与 GLFW 和 GLEW 一起使用。我正在使用着色器渲染所有内容,但深度缓冲区似乎不起作用。 我用于 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);
这就是它的样子:
【问题讨论】:
标签: c++ opengl shader glfw depth-buffer