i have written a simple OBJ-file loader to render meshes using OpenGL. But there is a problem displaying the loaded mesh. It seems that faces that from the background (far) are displayed above the front faces.

To illustrate the problem i have rendered a little example picture (Blender monkey).

Blender monkey mesh face order problem

I am using really simple shaders:

Vertex shader

#version 330

layout (location = 0) in vec3 vert;
layout (location = 1) in vec2 uv;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

out vec2 frag_uv;
out vec3 frag_vert;

void main()
    gl_Position  = vec4(vert, 1);
    gl_Position *= model;
    gl_Position *= view;
    gl_Position *= projection;

    frag_vert = vec3(vec4(vert, 1) * model);
    frag_uv = uv;

Fragment shader

#version 330

in vec2 frag_uv;
in vec3 frag_vert;

out vec4 color;

void main()
    color = vec4(frag_vert.x, frag_vert.y, frag_vert.z, 1.0);

The mesh is rendered using a VBO and a VAO. I have no clue ehat i am doing wrong. Thank you, and a nice christmas :)

  • 1
    \$\begingroup\$ How did you set up your depth buffer? \$\endgroup\$ – sam hocevar Dec 24 '15 at 13:31
  • \$\begingroup\$ I did not set up a depth buffer \$\endgroup\$ – user76572 Dec 24 '15 at 13:32
  • \$\begingroup\$ Is Your near plane set to 0? \$\endgroup\$ – The Light Spark Dec 24 '15 at 13:35
  • \$\begingroup\$ I forgot to enable depth testing. This is solved. Thank you. glEnable(GL_DEPTH_TEST) was missing. \$\endgroup\$ – user76572 Dec 24 '15 at 13:37
  • \$\begingroup\$ @Johannes If you have solved your problem please consider answering your own question instead of just commenting. \$\endgroup\$ – Christer Dec 24 '15 at 17:19


Depth testing was not enabled:


... fixed the Problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy