title: OpenGL: object order in zbuffer (LWJGL 3 and GLFW 3)
body: <p>I'm back with "traditional" depth test problem; I've tried many things, googled ungooglable, but still didn't find solution.</p>
  
  <p>I render some objects using Java and LWJGL 3 (with GLFW), cubes are rendered with z-buffer enabled (I think):</p>
  
  <pre><code>// renderer setup
  @Override
  public void setup() {
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glClearDepth(1.0f);
      glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glShadeModel(GL_SMOOTH);
      glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
      glEnable(GL_TEXTURE_2D);
      // cull face? Maybe? .... dunno
      glEnable(GL_CULL_FACE);
      glCullFace(GL_BACK);
      // here, hey, OpenGL, do you see this thing!?
      glEnable(GL_DEPTH_TEST);
      glDepthMask(true);
      glDepthFunc(GL_LEQUAL);
      glFrontFace(GL_CW);
      glDisable(GL_DITHER);
  }
  </code></pre>
  
  <p>But if I render cubes (using VBOs), they overdraw each other.</p>
  
  <pre><code>// window creation
      if(glfwInit() != GL_TRUE) {
          throw new DeRiveanException("Cannot init GLWF subsystem.");
      }
      glfwDefaultWindowHints();
      glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
      glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
      long monitorHandle = glfwGetPrimaryMonitor();
      ByteBuffer videModeBuffer = glfwGetVideoMode(monitorHandle);
      setWidth(GLFWvidmode.width(videModeBuffer) * 3 / 4);
      setHeight(GLFWvidmode.height(videModeBuffer) * 3 / 4);
      if((windowHandle = glfwCreateWindow(getWidth(), getHeight(), "title goes here", 0, 0)) == 0) {
          throw new DeRiveanException("Cannot create window handle. Da fucQ!?");
      }
      glfwSetInputMode(windowHandle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
      glfwSetWindowPos(windowHandle, (GLFWvidmode.width(videModeBuffer) - getWidth()) / 2, (GLFWvidmode.height(videModeBuffer) - getHeight()) / 2);
      glfwMakeContextCurrent(windowHandle);
      glfwSwapInterval(GL_FALSE);
      glfwSetInputMode(windowHandle, GLFW_STICKY_KEYS, GL_TRUE);
      glfwSetCursorPos(windowHandle, getWidth() / 2, getHeight() / 2);
      GLContext.createFromCurrent();
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xT5Ke.png" alt="wrong object order"></p>
  
  <p><strong>EDIT</strong>
  Ok, now I know, that I have depth 24bit buffer, so bug is in other place :( ....</p>
  
  <p><strong>Partially GOTCHA</strong>
  ...I have reaped engine to smallest possible pieces and found, that everything is OK until I connect camera. Its strange, but if I can walk and look around, z-buffer will die; if I set static view, z-buffer happily live until it's end.... </p>