2

I'm using openGL with GLFW and GLEW. I'm rendering everything using shaders but it seems like the depth buffer doesn't work. The shaders I'm using for 3D rendering are:

Vertex Shader

#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);
};

Fragment Shader

#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;
};

and I'm also enabling the depth buffer and cull face

glEnable(GL_DEPTH_BUFFER);
glDepthFunc(GL_NEVER);

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);

This is how it is looking:

2 Answers 2

2

You're not enabling depth testing. Change glEnable(GL_DEPTH_BUFFER); into glEnable(GL_DEPTH_TEST); This error could have been detected using glGetError().

Sign up to request clarification or add additional context in comments.

2 Comments

@LuizAugustoWendt: Also, you used glDepthFunc(GL_NEVER), which means the depth test will never pass. So all fragments ought to be culled. The only reason something appeared on the screen is because you enabled the wrong thing.
Yep, I was using never just to test if it the depth test was working :~
2

Like SurvivalMachine said, change GL_DEPTH_BUFFER to GL_DEPTH_TEST. And also make sure that in your main loop you are calling glClear(GL_DEPTH_BUFFER_BIT) before any drawing commands.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.