problem of glReadPixels

related code is as below:

int ww = glutGet( (GLenum)GLUT_WINDOW_WIDTH );
int wh = glutGet( (GLenum)GLUT_WINDOW_HEIGHT );

glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

intensitymap=(GLushort*)malloc(wwwh6);

glReadBuffer(GL_FRONT);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0,0,ww,wh,GL_RGB,GL_UNSIGNED_SHORT,intensitymap);

The problem is:
because the image background is white, there should be a lot of pixels with value of r=65535,g=65535 and b=65535.
but actually, it is not. a lot of other values.

and, when I save this array to a file, for example, ppm image file, and then open it in photoshop, the rendering result is right.

It almost drive me mad!!!

help. and thanks a lot!!!

Hello,
maybe you’re looking at your array while debugging. In this case the contents of your front buffer…is just your debugging window, not the actual image that would appear otherwise.

Are you sure you’re clearing the front color buffer and not the back color buffer? If you’re clearing the back buffer you’ll need to do glutSwapBuffers() before reading from the front buffer.

-Brian

Thank you very much!

Actually, it is because I am working in debug mode.

thanks again!!!