title: Deferred Rendering Skybox OpenGL
body: <p>I've just implemented deferred rendering and am having trouble getting my skybox working. I try rendering my skybox at the very end of my rendering loop and all I get is a black screen. Here's the rendering loop:</p>
  
  <pre><code>    //binds the fbo
      gBuffer.Bind();
  
      //the shader that writes info to gbuffer
      geometryPass.Bind();
  
      glDepthMask(GL_TRUE);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glEnable(GL_DEPTH_TEST);
      glDisable(GL_BLEND);
  
      //draw geometry
      geometryPass.SetUniform("model", transform.GetModel());
      geometryPass.SetUniform("mvp", camera.GetViewProjection() * transform.GetModel());
  
      mesh3.Draw();
  
      geometryPass.SetUniform("model", transform2.GetModel());
      geometryPass.SetUniform("mvp", camera.GetViewProjection() * transform2.GetModel());
      sphere.Draw();
  
      glDepthMask(GL_FALSE);
      glDisable(GL_DEPTH_TEST);
  
      glEnable(GL_BLEND);
      glBlendEquation(GL_FUNC_ADD);
      glBlendFunc(GL_ONE, GL_ONE);
  
      glBindFramebuffer(GL_FRAMEBUFFER, 0);
      glClear(GL_COLOR_BUFFER_BIT);
  
      //shader that calculates lighting
      pointLightPass.Bind();
      pointLightPass.SetUniform("cameraPos", camera.GetTransform().GetPosition());
  
      for (int i = 0; i &lt; 2; i++)
      {
          pointLightPass.SetUniformPointLight("light", pointLights[i]);
          pointLightPass.SetUniform("mvp", glm::mat4(1.0f));
          //skybox.GetCubeMap()-&gt;Bind(9);
          quad.Draw();
      }
  
      //draw skybox
      glEnable(GL_DEPTH_TEST);
      skybox.Render(camera);
  
      window.Update();
      window.SwapBuffers();
  </code></pre>
  
  <p>The following is the skybox's render function</p>
  
  <pre><code>glCullFace(GL_FRONT);
  glDepthFunc(GL_LEQUAL);
  
  m_transform.SetPosition(camera.GetTransform().GetPosition());
  m_shader-&gt;Bind();
  
  m_shader-&gt;SetUniform("mvp", camera.GetViewProjection() * m_transform.GetModel());
  m_shader-&gt;SetUniform("cubeMap", 0);
  
  m_cubeMap-&gt;Bind(0);
  m_cubeMesh-&gt;Draw();
  
  glDepthFunc(GL_LESS);
  glCullFace(GL_BACK);
  </code></pre>
  
  <p>And here is the skybox's vertex shader:</p>
  
  <pre><code>layout (location = 0) in vec3 position;
  
  out vec3 TexCoord;
  
  uniform mat4 mvp;
  
  void main()
  {
      vec4 pos = mvp * vec4(position, 1.0);
      gl_Position = pos.xyww;
      TexCoord = position;
  }
  </code></pre>
  
  <p>The skybox's fragment shader just sets the output color to <code>texture(cubeMap, TexCoord)</code>.
  As you can see from the vertex shader, I'm setting the position's <code>z</code> component to be <code>w</code> so that it will always have a depth of 1. I am also setting the depth function to be <code>GL_LEQUAL</code> so that it will fail the depth test. Should this not only draw the skybox in places where other objects weren't already drawn? Why does it result in a black screen? </p>
  
  <p>I know I have set up the skybox correctly because if I just draw the skybox by itself it shows up just fine.</p>