c++ - 深度缓冲区似乎不起作用 - OpenGL Shader

标签 c++ opengl shader glfw depth-buffer

我正在将 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);

这就是它的样子:

最佳答案

您没有启用深度测试。将 glEnable(GL_DEPTH_BUFFER); 更改为 glEnable(GL_DEPTH_TEST); 使用 glGetError() 可以检测到此错误。

关于c++ - 深度缓冲区似乎不起作用 - OpenGL Shader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38144958/

相关文章:

performance - glBitmap问题

swift - 如何在 SceneKit 中使用 SCNBufferBindingBlock?

c++ - 只为一个对象创建一个类

c++ - 不匹配的类型 'std::chrono::_V2::steady_clock' 和 'std::chrono::_V2::system_clock'

c++ - 尝试在 OpenGL/SFML 中实现鼠标外观 "camera"

Opengl 三角形包含孔并且有时会消失

c++ - 2 智能感知 : argument of type "const char *" is incompatible with parameter of type "LPCWSTR"

C++:从 cin 流中读取字符串并存储以空格分隔的值

glsl - 如何绘制GLSL中多个函数生成的形状?

opengl - imageStore 是原子的吗?