PDA

View Full Version : glReadPixels



mphanke
06-03-2002, 08:17 AM
Hi,

can somebody point me out why, or even better in which cases, glReadPixels doesn't find the right depth coordinates?

I'm using



glReadPixels(oldX - winX, oldY - winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pixel);

The problem is as soon as I have rotated the model only slightly I get an error of at least 10% (depth not found, so pixel is something close to zero (5.1e-308)).
That's my Draw-func, in case it is needed.



GLvoid __fastcall View: http://www.opengl.org/discussion_boards/ubb/biggrin.gifraw(bool trans)
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(GLTranslateX, 0.0, 0.0);
glTranslated(0.0, GLTranslateY, 0.0);
glTranslated(0.0, 0.0, GLTranslateZ );

glPushMatrix();
glRotated(GLRotateX,1.0,0.0,0.0);
glRotated(GLRotateY,0.0,1.0,0.0);

glGetDoublev(GL_MODELVIEW_MATRIX, mvMatrix);

if(ObjList)
{
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFF USE,mat_ambient);

ObjList->Draw(GL_TRIANGLE_STRIP);

glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFF USE,mat_ones);

}
glDisable(GL_LIGHT1);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);

glPopMatrix();//Transform
glPopMatrix();//Rotate
}

Further I would like to know how to deal with the glPolygonOffset. I tried couple things, yes I searched the forum and I read the snippet in the Red Book, but it didn't really help me.
I'm trying to draw a patch on top of an object. The coords for the patch are retrieved with the function above and gluUnproject.

Thanks,

Martin

[This message has been edited by mphanke (edited 06-03-2002).]

mphanke
06-04-2002, 07:24 AM
Hi,

just in case someone searches the forum and tries to find an answer on this:

You have to do the glReadPixels exactly where you draw your model. Otherwise you will not be able to retrieve the right depth coords.

Greets,

Martin