title: How to write to the OpenGL Depth Buffer
body: <p>I'm trying to implement an old-school technique where a rendered background image AND preset depth information is used to occlude other objects in the scene.</p>
  
  <p>So for instance if you have a picture of a room with some wires hanging from the ceiling in the foreground, these are given a shallow depth value in the depthmap, and when rendered correctly, allows the character to walk "behind" the wires but in front of other objects in the room.</p>
  
  <p>So far I've tried creating a depth texture using:</p>
  
  <p><code>glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Image.GetWidth(), Image.GetHeight(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, pixels);</code></p>
  
  <p>Then just binding it to a quad and rendering that over the screen, but it doesnt write the depth values from the texture.</p>
  
  <p>I've also tried:</p>
  
  <p><code>glDrawPixels(Image.GetWidth(), Image.GetHeight(), GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, pixels);</code></p>
  
  <p>But this slows down my framerate to about 0.25 fps...</p>
  
  <p>I know that you can do this in a pixelshader by setting the gl_fragDepth to a value from the texture, but I wanted to know if I could achieve this with non-pixelshader enabled hardware?</p>