Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vec2 GetOGLPos(int x, int y)
- {
- 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);
- Vec2 pos;
- pos.x = posX;
- pos.y = posY;
- return pos;
- }
Add Comment
Please, Sign In to add comment