PDA

View Full Version : problem of glReadPixels



weicao
03-24-2004, 12:02 AM
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(ww*wh*6);

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

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!!!

CoinCoin
03-24-2004, 06:15 AM
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.

Brian Paul
03-26-2004, 07:20 AM
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

weicao
03-29-2004, 04:56 AM
Thank you very much!

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

thanks again!!!