title: Rendering a framebuffer to texture wont work
body: <p>I am trying to create a depth map in OpenGL and for some reason the framebuffer wont write to the texture, I tried multiple things to fix it but it doesn't seem to work.</p>
  
  <p>Here is what I did:</p>
  
  <p>This is the generation of the framebuffer and the texture:</p>
  
  <pre><code>glGenFramebuffers(1, &amp;_DepthMapFBO);
  glBindFramebuffer(GL_FRAMEBUFFER, _DepthMapFBO);
  
  glGenTextures(1, &amp;_DepthMapTex);
  glBindTexture(GL_TEXTURE_2D, _DepthMapTex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, DEPTH_TEXTURE_WIDTH, DEPTH_TEXTURE_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
  
  //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _DepthMapTex, 0);
  glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _DepthMapTex, 0);
  
  glDrawBuffer(GL_NONE);
  glReadBuffer(GL_NONE);
  
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  </code></pre>
  
  <p>(In the above I tried replacing <code>glTexImage2D</code> with <code>glTexStorage2D</code> and I tried replace <code>glFramebufferTexture</code> with <code>glFramebufferTexture2D</code>, both didn't work)</p>
  
  <p>Then (There  is stuff before this but they work find, I checked) I rendered the framebuffer as follows:</p>
  
  <pre><code>_DepthProgram.Use();
  // Setting uniforms here
  glViewport(0, 0, DEPTH_TEXTURE_WIDTH, DEPTH_TEXTURE_HEIGHT);
  glBindFramebuffer(GL_FRAMEBUFFER, _DepthMapFBO);
  glClear(GL_DEPTH_BUFFER_BIT);
  // Rendering the scene here
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  </code></pre>
  
  <p>These are the shaders I use:</p>
  
  <p>(Vertex)</p>
  
  <pre><code>#version 410 core
  
  layout(location = 0) in vec3 Position;
  
  uniform mat4 LightSpaceMatrix;
  uniform mat4 Model;
  
  void main()
  {
      gl_Position = LightSpaceMatrix * Model * vec4(Position, 1.0);
  }
  </code></pre>
  
  <p>(Fragment)</p>
  
  <pre><code>#version 410 core
  
  void main()
  {
      // gl_FragDepth = 0.0;
  }
  </code></pre>
  
  <p>I tried rendering the texture to a plane and it came out totally white (I Checked there was supposed to be other values), <strong>As you can see in the fragment shader, I tried to explicitly write to the <code>gl_FragDepth</code> but it didn't change the texture, it kept it white (1.0)</strong>.</p>
  
  <p>I looked all over the internet and looked at <a href="https://learnopengl.com/#!Advanced-Lighting/Shadows/Shadow-Mapping" rel="nofollow noreferrer">learnopengl.com</a> and everybody seem to be doing the same as me, did I miss something?</p>
  
  <p>(<strong><em>I double checked and I am rendering the texture to the plane right, I replaced the <code>glBindTexture</code> with another one and it rendered the texture</em></strong>)</p>
  
  <p>If I am missing some information please let me know.</p>
  
  <p>EDIT: By the way, I don't get any error with <code>glGetError</code>.</p>