title: Texturing two triangles (rectangle) with a depth texture gives all red colors
body: <p>I am implementing shadow mapping in my program, and as intermediate step I want to be able to see the depth texture that has been generated after the first light pass, however all I see on the screen is red, relevant code:</p>
  
  <pre><code>@Override
  protected void render(final double msDelta) {
      super.render(msDelta);
  
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);
  
      //Light pass
      glViewport(0, 0, 4096, 4096);
      ...
  
      //Draw pass
      glViewport(0, 0, screenWidth, screenHeight);
      ...
  
      //Visualize depth texture
      if (visualDepthTexture) {
          glViewport(100, screenHeight - (screenHeight / 5) - 100, screenWidth / 5, screenHeight / 5);
          glClearDepthf(1f);
          glClear(GL_DEPTH_BUFFER_BIT);
          glActiveTexture(GL_TEXTURE0);
          depthTexture.bind();
          glDrawBuffer(GL_BACK);
          depthBox.draw(0);
          depthTexture.unbind();
      }
  }
  </code></pre>
  
  <p>where <code>depthTexture</code>:</p>
  
  <pre><code>    //shadow FBO and texture
      depthFBO = new FrameBufferObject().create().bind();
      depthTexture = new Texture2D().create().bind()
              .storage2D(11, GL_DEPTH_COMPONENT32F, 4096, 4096)   //11 is log2(4096)
              .minFilter(GL_LINEAR)
              .magFilter(GL_LINEAR)
              .compareMode(GL_COMPARE_REF_TO_TEXTURE)
              .compareFunc(GL_LEQUAL);
      depthFBO.texture2D(GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, depthTexture, 0)
              .unbind();
      depthTexture.unbind();
  </code></pre>
  
  <p>And <code>depthBox.draw(0)</code> will draw 6 vertices in <code>GL_TRIANGLES</code> mode, using the following shaders:</p>
  
  <p><code>depth-box.vs.glsl</code></p>
  
  <pre><code>#version 430 core
  
  void main(void) {
      const vec4 vertices[6] = vec4[](
          vec4(-1.0, -1.0, 1.0, 1.0),
          vec4(-1.0, 1.0, 1.0, 1.0),
          vec4(1.0, 1.0, 1.0, 1.0),
  
          vec4(1.0, 1.0, 1.0, 1.0),
          vec4(1.0, -1.0, 1.0, 1.0),
          vec4(-1.0, -1.0, 1.0, 1.0)
      ); 
  
      gl_Position = vertices[gl_VertexID];
  }
  </code></pre>
  
  <p><code>depth-box.fs.glsl</code></p>
  
  <pre><code>#version 430 core
  
  layout(binding = 0) uniform sampler2D shadow_tex;
  
  out vec4 color;
  
  void main(void) {
      color = vec4(texture2D(shadow_tex, gl_FragCoord.xy));
  }
  </code></pre>
  
  <p>What I am trying to achieve is that the depth texture gets converted to grayscale (to see where shadow should occur), and that the two triangles in the small viewport get textured with that result.</p>