I sent a test version of my in-development game to some friends, and they found out that the Depth Test in OpenGL does not work on Nvidia cards. I'm using LWJGL.

I use my own matrices and send them to the shader, and at the start of evey game loop I use

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // clear the display

On an Nvidia card, you can see mountains through other mountains and stuff. On my Radeon HD 6650M it works perfectly fine. Any ideas?

I don't have anything special in the shaders—just some basic lighting calculations. I dont touch the gl_FragDepth.

Here's a screenshot (with placeholder textures):

Depth-Test bug on NVidia cards

I use these calculations for the Projection Matrix:

public Matrix4f getProjectionMatrix() {
    // Setup projection matrix
    Matrix4f projectionMatrix = new Matrix4f();
    float fieldOfView = 40.0f;
    float aspectRatio = (float)Display.getWidth() / (float)Display.getHeight();
    float near_plane = 0.1f;
    float far_plane = 1000f;

    float y_scale = coTangent((float) Math.toRadians(fieldOfView / 2f));
    float x_scale = y_scale / aspectRatio;
    float frustum_length = far_plane - near_plane;

    projectionMatrix.m00 = x_scale;
    projectionMatrix.m11 = y_scale;
    projectionMatrix.m22 = -((far_plane + near_plane) / frustum_length);
    projectionMatrix.m23 = -1;
    projectionMatrix.m32 = -((2 * near_plane * far_plane) / frustum_length);
    projectionMatrix.m33 = 0;
    return projectionMatrix;
  • 2
    \$\begingroup\$ I'll ask a dumb question: did you glEnable(GL_DEPTH_TEST)? \$\endgroup\$ Commented May 26, 2013 at 16:48
  • \$\begingroup\$ Yes I did haha :) \$\endgroup\$
    – Basaa
    Commented May 26, 2013 at 17:22
  • 2
    \$\begingroup\$ Dumb question vol. 2: Did you create a depth buffer? \$\endgroup\$ Commented May 26, 2013 at 17:29
  • \$\begingroup\$ Uhm. No idea. :) \$\endgroup\$
    – Basaa
    Commented May 26, 2013 at 19:02
  • 5
    \$\begingroup\$ not in a perfect world, but actual driver implementations vary between makers, models, and even versions of the same driver. It is completely possible that the way you initialize your gl context is triggering some undefined behavior, which the ATI driver understands as "create depth buffer" and the nVidia driver understands as "don't create depth buffer". To avoid this you have to be extra verbose on everything, and sometimes even have different code paths for different video cards. Which interfacing library are you using, and on what language? \$\endgroup\$ Commented May 28, 2013 at 13:24

1 Answer 1


Make sure you request a depth buffer from LWJGL by passing a PixelFormat to your call of Display.create. Like so:

Display.create(new PixelFormat(4,24,0,4));

The 24 indicates a 24 bit depth buffer.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .