title: How to set an invisible occluder in OpenGL 2
body: <p>I have two objects on a 3D scene (rendered with <a href="https://www.opengl.org/sdk/docs/man2/xhtml/glDrawElements.xml" rel="nofollow noreferrer">glDrawElements</a>). When one of them passes behind the other, it is occluded and not visible anymore (the normal behaviour anyone would expect).</p>
  
  <p>What I want to do next, is to <strong>make invisible the foreground object</strong> (I want the background object (blue) to disappear when it goes behind the foreground object (dashed) and re-appear when it comes back to the other side, keeping the foreground object un-rendered).</p>
  
  <p><img src="https://i.stack.imgur.com/GAeZN.png" alt="enter image description here"></p>
  
  <p><em>Only render the blue parts!</em></p>
  
  <p>I'm using OpenGL 2, though I'm pretty new on it. </p>