Jump to content
  • Advertisement
Sign in to follow this  

OpenGL gluUnProject issue

This topic is 3494 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

I am having a problem where gluUnProject is returning skewed results for the y-axis. In an orthographic view, I have a scene with an object created at the world origin (0,0,0). If I click on the world origin with my mouse, I will get different results for the y-axis, based on my current zoom level of the orthographic projection. Here is how I'm getting the world position based on the screen position (all done with Python using PyOpenGL):
model = glGetDoublev( GL_MODELVIEW_MATRIX )
proj = glGetDoublev( GL_PROJECTION_MATRIX )
z = glReadPixels( x, config.g_window_size.y - y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT )
viewport = [ 0, 0, config.g_window_size.x, config.g_window_size.y ]
world_pos = gluUnProject( x, config.g_window_size.y - y, z, model, proj, viewport )
Here is how I'm currently doing the zoom for the orthographic view (in my camera class):
glScalef( 1.0 / self.m_ortho_zoom, 1.0 / self.m_ortho_zoom, 1.0 / self.m_ortho_zoom )
glTranslatef( self.m_position.x, self.m_position.z, 0.0 )
For example, at the default zoom level, when I click at the world origin, I will get a value of (0, 4, 0). If I change the zoom level, then the y-axis value will change. I'm not really sure what I'm doing wrong, so I'm hoping that someone can shed some light on this for me. If you're curious, this website has a video on the front page that shows what I'm working on. http://www.sugarpy.com/ Thanks!

Share this post

Link to post
Share on other sites
I solved this. I had an incorrect value in my glViewport( ) call when initializing OpenGL.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!