PDA

View Full Version : gluUnProject



pramod
01-04-2007, 03:03 AM
I have an MFC_OpenGL Application where I have used gluUnProject() function in it.... & the code goes like this:

glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );

winX = (float)x;
winY = (float)viewport[3] - (float)y;
glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

I have problem in glGetDoublev(GL_MODELVIEW_MATRIX, modelview), here I am not able to get model matrix, when i debug, i get the garbage values for all the 16 values in the MODEL MATRIX...

So plzzzzzz help me in this..

k_szczech
01-04-2007, 06:28 AM
How are your projection and modelview variables defined?

jtipton
01-04-2007, 07:26 AM
Are your matrices pointers to floats? If they are doubles, then I would think you are getting garbage into the matrices before you try and retrieve them, possibly with a glLoadMatrix or glMultMatrix.

pramod
01-04-2007, 08:25 PM
I have used the same code in different MFC Appln where it's working fine only when I maximum the window (if the window is restored back, i am not able to get the same value of the mouse pointer in a 3D space), but it's not working in my present MFC appln, is this anything to do with setting up or intializing the viewport!!!!!!!!

Thank U

pramod
01-04-2007, 08:28 PM
How are your projection and modelview variables defined?

variables are defined as:
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;

glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );

winX = (float)x;
winY = (float)viewport[3] - (float)y;
glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

return Vector(posX, posY, posZ);

wilburn
01-04-2007, 08:54 PM
Please make sure first that your OpenGL render context is valid before calling all OpenGL commands.

wilburn
01-04-2007, 08:56 PM
Please make sure then that your glPushMatrix and glPopMatrix are used as a pair.