title: Using glBlitFramebuffer to display a texture
body: <p>I am trying to implement a simple multipass rendering scheme. I first blit the multisampled version of the scene to a FBO <code>beforeEffectsContext.fbo</code>. If I then blit this to the application provided FB it works fine. But I want to do another pass on the scene to blur it. I therefore bind the texture in the <code>COLOR_ATTACHMENT0</code> in the <code>beforeEffectsContext.fbo</code>, sample it, drawing a quad with a blur effect added to another framebuffer <code>blurContext.fbo</code>.</p>
  
  <p>If I know display the content of <code>blurContext.fbo</code>'s color attachment to the screen using the same approach with a quad and a texture sampling, it works and I get a blurred scene.</p>
  
  <p>But if I try to use <code>glBlitFramebuffer()</code> instead in this step, I get a black screeen. The problem seems to be in my misunderstanding of the blitting process and FBOs.</p>
  
  <p>Initialization code for the <code>blurContext.fbo</code>:</p>
  
  <pre><code>// BeforeEffects Framebuffer
  glGenFramebuffers(1, &amp;renderContext-&gt;beforeEffectsContext.fbo);
  glBindFramebuffer(GL_FRAMEBUFFER, renderContext-&gt;beforeEffectsContext.fbo);
  
  glGenTextures(1, &amp;renderContext-&gt;beforeEffectsContext.colorAttachment);
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, renderContext-&gt;beforeEffectsContext.colorAttachment);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 800, 600, 0, GL_RGBA, GL_FLOAT, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderContext-&gt;beforeEffectsContext.colorAttachment, 0);
  
  // Blur Framebuffer
  glGenFramebuffers(1, &amp;renderContext-&gt;blurContext.fbo);
  glBindFramebuffer(GL_FRAMEBUFFER, renderContext-&gt;blurContext.fbo);
  
  glGenTextures(1, &amp;renderContext-&gt;blurContext.colorAttachment);
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, renderContext-&gt;blurContext.colorAttachment);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 800, 600, 0, GL_RGBA, GL_FLOAT, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderContext-&gt;blurContext.colorAttachment, 0);
  </code></pre>
  
  <p>Rendering:</p>
  
  <pre><code>// Draw to the MSampled scene to the BeforeEffects framebuffer
  glBindFramebuffer(GL_READ_FRAMEBUFFER, renderContext-&gt;multiSamplingContext.fbo);
  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, renderContext-&gt;beforeEffectsContext.fbo);
  glBlitFramebuffer(0, 0, 800, 600, 0, 0, 800, 600, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
  
  // Sample the texture attached to the beforeEffects FBO and draw to the blur FBO
  glBindTexture(GL_TEXTURE_2D, renderContext-&gt;beforeEffectsContext.colorAttachment);
  glBindFramebuffer(GL_FRAMEBUFFER, renderContext-&gt;blurContext.fbo);
  glViewport(0, 0, 800, 600);
  
  glUseProgram(renderContext-&gt;blurProgramContext.program);
  glBindVertexArray(renderContext-&gt;vaoBlur);
  
  glDrawArrays(GL_QUADS, 0, 4);
  
  glUseProgram(0);
  glBindVertexArray(0);
  
  // Blit the content of the blur FBO to the app-provided Framebuffer (doesn't work, black screen)
  glBindFramebuffer(GL_READ_FRAMEBUFFER, renderContext-&gt;blurContext.fbo);
  glReadBuffer(GL_COLOR_ATTACHMENT0);
  glBindFramebuffer(GL_DRAW_BUFFER, 0);
  glViewport(0, 0, 800, 600);
  glBlitFramebuffer(0, 0, 800, 600, 0, 0, 800, 600, GL_COLOR_BUFFER_BIT,
      GL_NEAREST);
  </code></pre>