glRead/drawpixels over FBO

I want to read all the pixel of my offscreen render, but when I call the glreadpixels, it returns to me only the window pixel value, and not the offscreen pixel’s value.

First I think that it can be for an incorrect FBO setup, but I had not found any error.

So I want to know if glreadpixel read all the buffer or not…

Be sure you call glBindFramebuffer with valid FBO before glReadPixels.

It works fine for me (NV cards).

Beware: glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0)
will switch back to reading from Window.

I’ve call glbindframebuffer before glreadpixels, but it read nonsense value…this is my config:
FOR GLREADPIXELS:

glReadPixels(0, 0, dimX, dimY, GL_RGBA, GL_FLOAT, imagePixels);

AND THIS IS THE TEXTURE FBO:

glBindTexture(GL_TEXTURE_2D, color_tex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, dimX, dimY, 0,
GL_RGBA8, GL_FLOAT, NULL);

	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, color_tex, 0);

somethings wrong?

  1. BindFBO(true)
  2. glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
  3. glReadPixels()
  4. BindFBO(false)

Also, when you Bind a texture make sure which texture unit is active or just say glActiveTexture(GL_TEXTURE0) or some other texture unit. These are common mistake easily overlooked.

You dont’ seem to initialize the contents of the texture.

What did you mean with “context of the texture”?

I follow your istruction and I make a little step over, but my offscreen render seems to working wrong. Maybe for this “context of the texture”?

Your FBO is probably not complete.
After glFramebufferTexture2D()
call following to be sure the FBO is OK.

  GLenum status; 
  status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 
  if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
    // report error
  }

I think FBO isn’t complete because in

 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, dimX, dimY, 0, GL_RGBA8, GL_FLOAT, NULL); 

the second GL_RGBA8 isn’t a correct value but GL_RGBA is.

My FBO seems to be ok, this is my problem:

Render off-screen

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,mRenderer.fb);

glDrawElements( GL_TRIANGLES, kNumVertices, GL_UNSIGNED_INT, &mTriBufferIndices[0] ); 
 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fb);
glReadPixels(0, 0, dimX, dimY, GL_RGBA, GL_FLOAT, imagePixels);
    1. Draw the pixel

but that pixel are incomplete, in fact in the offscreen rectangle there’s only the window clear color without the 3D image. So when I call gldrawelements with previosly the glbindframebufferEXT, the 3D object seems to disappear…while if I use only the gldrawelements without the glbindframebufferEXT the 3D object is rendered on the window(but maybe not in the offscreen buffer).

Any idea? thanks…