Guest User

Untitled

a guest
Jan 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. Vec2 GetOGLPos(int x, int y)
  2. {
  3.     GLint viewport[4];
  4.     GLdouble modelview[16];
  5.     GLdouble projection[16];
  6.     GLfloat winX, winY, winZ;
  7.     GLdouble posX, posY, posZ;
  8.  
  9.     glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
  10.     glGetDoublev( GL_PROJECTION_MATRIX, projection );
  11.     glGetIntegerv( GL_VIEWPORT, viewport );
  12.  
  13.     winX = (float)x;
  14.     winY = (float)viewport[3] - (float)y;
  15.     glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
  16.  
  17.     gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
  18.  
  19.     Vec2 pos;
  20.     pos.x = posX;
  21.     pos.y = posY;
  22.  
  23.     return pos;
  24. }
Add Comment
Please, Sign In to add comment