How to convert the contents in frame buffer into a 2D array?

Hi guys,

I would like to know how to convert the content in frame buffer into a 2D array (pixel by pixel)?

e.g. consider the following code:

glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();

The code above draw a rectangle on the screen,

I would like get the following:

000000000000000000000000000
000001111111111111111100000
000001111111111111111100000
000001111111111111111100000
000001111111111111111100000
000001111111111111111100000
000001111111111111111100000
000001111111111111111100000
000001111111111111111100000
000001111111111111111100000
000000000000000000000000000

Thanks.

Search for glReadPixels.
If you need it as one bit per pixel use GL_BITMAP as type.
Mind that OpenGL coordinates are bottom-left origin when interpreting your readback data.

Thanks!