Hi,
I'm trying to do the post-effect Depth of Field using a deferred shading technique.

My idea is to make a downsample of the final shape image (the one with all the geometry and lights) in orther to apply a gaussian filter more efficiently.
I create a FBO to save this downsampled image, I bind it, I scale the viewport to with / 2 and height /2 and then I paint into it.
The problem I have is instead of painting the whole texture with a "zoom", it only paints the part that can fill the smaller texture... (I'll put images to explain
it better).

Here you have the bind in the FBO:

Code :
// Binding the DOF buffer
  glBindFramebuffer(GL_FRAMEBUFFER, dof_buffer_.id);
 
  // Texture with the half of the size to make the downsample.
  glBindTexture(GL_TEXTURE_RECTANGLE, dof_buffer_.tex_id);
  glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGB32F,
    width / 2, height / 2, 0, GL_RGB,
    GL_FLOAT, NULL);
 
  glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
  glBindTexture(GL_TEXTURE_RECTANGLE, 0);
 
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
    GL_TEXTURE_RECTANGLE, dof_buffer_.tex_id, 0);
  // See if framebuffer was created correctly
  GLenum framebuffer_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  if (framebuffer_status != GL_FRAMEBUFFER_COMPLETE) {
    tglDebugMessage(GL_DEBUG_SEVERITY_HIGH, " DOF framebuffer bind not complete");
    return false;
  }
 
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
  return true;


Here you have the code of the render process: (now I'm just testing painting only the ambient texture of the Gbuffer).

Code :
 
//Before DOF I create Gbuffer, quad directional light and pointlights.
...
 
// DOF effect
    //Downsampling the image.
    glBindFramebuffer(GL_FRAMEBUFFER, dof_buffer_.id);
    glUseProgram(program_dof_downsample_);
    glClear(GL_COLOR_BUFFER_BIT);
 
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_RECTANGLE, gbuffer_.tex_ambient_id);
    glUniform1i(glGetUniformLocation(program_dof_downsample_, "texture"), 0);
 
    glViewport(0, 0, 1280 / 2, 720 / 2);
 
    glBindVertexArray(light_quad_.vao);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    glBindTexture(GL_TEXTURE_RECTANGLE, 0);

and here you have the texture, the original and the downsampled:

Original:
Click image for larger version. 

Name:	texture_original.jpg 
Views:	172 
Size:	10.7 KB 
ID:	1810

Downsampled:
Click image for larger version. 

Name:	texture.jpg 
Views:	165 
Size:	21.2 KB 
ID:	1809

How can I downsample the whole image into a smaller texture??

Thank you very much!