View Full Version : gluUnProject with multiple viewports

Herr Bohm
12-27-2006, 07:00 AM
Im trying to get the opengl mouse coordinates of the 4 viewports that I have

// Set Viewport To Top Left And Draw Window
glViewport(0, this->S_OpenGLInfo.win32_height / 2, this->S_OpenGLInfo.win32_width / 2, this->S_OpenGLInfo.win32_height / 2);

POINT pos;
ScreenToClient(this->S_Win32Info[0].hwnd, &pos);
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)pos.x;
winY = (float)viewport[3] - (float)pos.y;
glReadPixels( pos.x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

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

With this code I dont get the correct coordinates.
And with the 2 lower viewports it gives me 0.0 for both posX and posY.
Thanks in advanced