glReadPixels

Hi there,
I’m trying to dump the color buffer of my program using glReadPixel.
The window size is 320 X 240 (x,y) I read from the buffer using:

glReadPixels(0, 0, 320, 240, GL_RGB, GL_UNSIGNED_BYTE, image);

The problem is that so can I only 1/4 of the image save (instead of all image)
I don´t know what´s the problem??
Does anyone have any idea?

Thanks
Best Regards,
Diego Carpintero

How much data do you actually read back? 1/4 or all of it?

What I mean is, if you clear your entire read back buffer to something known(0xAAAAAAAA), is the other 3/4 of the buffer untouched?

Double buffered framebuffers defaults to glReadBuffer(GL_BACK). Reading from correct buffer?

Extensions like PixelDataRange needs a glFinish after reading the pixels. Using this?

make sure you’re allocating 4X320X240 bytes for image and not just 320X240 bytes. I think 3X320X240 works as well…

  • Phil

>> How much data do you actually read back? 1/4 or all of it?
1/4 but I would like all
>> Double buffered framebuffers defaults to glReadBuffer(GL_BACK). Reading from correct buffer?
I make so:
glGetIntegerv(GL_DRAW_BUFFER, &colorBuffer);
glReadBuffer(colorBuffer);
glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,image);
>>Extensions like PixelDataRange needs a glFinish after reading the pixels. Using this?
Yes

I make so:
glGetIntegerv(GL_DRAW_BUFFER, &colorBuffer);
glReadBuffer(colorBuffer);
glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,image);

Consider this. You draw your scene as usual, and swap buffers so you can see on the screen what you just drew. Then you want to read back the frame buffer and do the above. The back buffer is still the draw buffer, but the content is in the front buffer, and you end up reading the wrong buffer.

It is important to read the right buffer at the right time when using double buffering. You should read the back buffer before swapping, and the front buffer after swapping. So our technique will only guarantee that you read from the buffer you draw to, but it doesn’t guarantee that it reads from the buffer the content is in.