Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

glReadPixlels() and gluUnProject()

This topic is 2685 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 using CML to get around using gluUnProject() and so far works fine, with one problem, when I use glReadPixels() I get correct results, but with no glReadPixels for my Z value I get incorrect values. Very minor values on the x,y values and Z is like 9 or 10 vs. 0 like glReadPixels gives me.

So what can I do to not use glReadPixels() or what is that I need to use it to get correct results. Clearly I need it as my x, y values aren't correct and should be -5,-5 on the lower left point I click, but I get -.5, -.5 IIRC when I click the same point....

Thanks!

BTW CML is located here.

http://cmldev.net/

Share this post


Link to post
Share on other sites
Advertisement
What's the connection between gluUnProject and glReadPixels here? What is it that you're trying to do?

Share this post


Link to post
Share on other sites

What's the connection between gluUnProject and glReadPixels here? What is it that you're trying to do?


I am doing picking, and getting the screen coordinates.

look at this

http://sites.google.com/site/vamsikrishnav/gluunproject

basically doing what he is doing.

and to quote him

[font="courier new,monospace"] Dont' get worried about window z co-ordinate which is given to this function. This value is obtained by using glReadPixels( x, viewport[3]-y, GL_DEPTH_COMPONENT, GL_FLOAT, &z );


[/font]

Share this post


Link to post
Share on other sites
The first thing I'd do is try to separate the glReadPixels() issue from how you're doing the un-projection. For example, if it's confirmed that gluUnProject() and cml::unproject_point() produce the same output given the same input (to within numerical limits), then you can remove the CML from the equation, since at that point you'll know that the problem is with the overall process itself rather than with how you're doing the un-projecting.

In other words, try to identify more specifically in what area the problem lies, and then focus on that area. (I'm not completely clear as to the exact nature of the problem itself, so I can't be much more specific than that.)

Share this post


Link to post
Share on other sites
Honestly people I have no idea what is wrong, other than the values are not what I need unless I use glReadPixels() and all the tutorials site show them using this process to determine the position... So I have no idea why this is so odd, and hard to understand what I am trying to do....

IMO the Z value unless is sent in my glReadPixels is wrong. I can't just send in a 0 or 1 and get correct results.

If I hard code the value I get from glReadPIxels() which is .9 I get the same results... But I can't just guess what value I want to send in e.g. 0 or 1 or .5 ect...

Share this post


Link to post
Share on other sites
Can you step back a minute and tell us what problem you're trying to solve? i.e. why you're implementing picking.

Are you trying to turn a point on the screen into a 3D location?
Without knowing the depth of a pixel (just the x/y) you can turn it into a ray (direction from camera) instead of a position. You can then use that ray to 'pick' an object from your scene.

Share this post


Link to post
Share on other sites
You don't need gluUnproject if you want to select an object.

A modern OpenGL program should do color picking (render each object with some unique color and glReadPixels to find out what object your mouse was on) or do the picking with some 3rd party mathematics library.[/quote]

from http://www.opengl.org/wiki/Common_Mistakes#Selection_and_Picking_and_Feedback_Mode

Share this post


Link to post
Share on other sites
If you set Z to 0, you should get almost the camera position (the position matching the pixel at the near plane).
If you set Z to 1, you should get the position matching the pixel at the far plane.

glReadPixels is usually used to get the Z or what was drawn at that pixel, which will give you an unprojected position ~ on the surface of the triangle that was drawn there.

Share this post


Link to post
Share on other sites
I am picking the object on the screen based on the mouse cursor. The user clicks the point or line and I am getting that position and doing a test against a AABB to determine if the object was clicked on.

The issue is the values make no sense, unless I get the depth from glReadPixels().... Meaning I KNOW the location of my points are -5, 5 in 1 unit increments and when I click on the far left bottom point I should see -5,-5 and I get that value if I use glReadPixels() depth value and send that in to gluUnProject() or CML's unprojectPoint(), but if I use 0 or 1 or some value out nowhere I WILL not get -5,-5 I get something like -.005, -.005 it's like the values are 1000 or 100 off from where it should be e.g. .005 * 1000 = 5; -.005 * 1000 = -5

Not sure if this clears up anything or not... I guess if no one can explain this I will just keep using glReadPixels() to get correct results, just odd no one here uses these examples that are all over the net on this topic.

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!