Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


gluProject/ glUnProject use examples?

This topic is 6106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can someone please explain to me clearly how to use gluProject/gluUnProject ? For example, I have a 2x2 grid of vertices, xy dimensions, z into screen, how do I transform mouse screen coord to 3d coord? Thanks.

Share this post

Link to post
Share on other sites
GLdouble pos3D_x, pos3D_y, pos3D_z;

// arrays to hold matrix information

GLdouble model_view[16];
glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

GLdouble projection[16];
glGetDoublev(GL_PROJECTION_MATRIX, projection);

GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

// get 3D coordinates based on window coordinates

gluUnProject(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 0.01,
model_view, projection, viewport,
&pos3D_x, &pos3D_y, &pos3D_z);

This code gets the position of the center of the screen and stores it in pos3D_x, y, z.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!