I have written an application in which I can click on a table top and get the x, y and z coordinates of where I click. I now want to draw objects upon the table but if I click on an object I still want the coordinates of the table behind it, not the coordinates of the surface of the object. Can I use glUnProject to achieve this and if so how?
gluUnProject simply maps the specified window coordinates into object coordinates using model, proj, and view. Used in a pair you can calculate a ray into the screen for ‘picking’.
If you want to look at a certain subset of geometry when ‘picking’ then do Ray intersections on the batch you are interested in rather than using the OpenGL Namestack.
It’s more efficient and will do what you require.
If you still want to ‘pick’ using OpenGL then AFAIK (I have not used it extensively) you can simply not add the items you wish to ignore to the name stack.
Once you have your pick ray you can use a fairly simple ray to plane, ray to xxx intersection algorithm. You will be able to find many examples if you Google.
gluUnProject is only giving you the tools you need to do the ‘picking’, you need to do some work yourself afterwards…