Jump to content
  • Advertisement
Sign in to follow this  
panda_

OpenGL [OpenGL] Picking mode

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

Welcome! I am writing my application using OpenGL. I try to implement Selection mode and it works but causes huge problems I can't solve: 1. When I initialize name stack and replace the name on it's top with 'glLoadName' I get more than one hit after comming back to the Render mode. I add that after the initialization the name stack I use only 'glPushName(0) only once so the stack should contain only one name. So how it's possible to get more than one hit?? 2. The next problem is probably connected with the first one, but I think I may have something wrong with a small viewport in cursor place as the whole scene would be as this viewport. I recall following instruction written in Delphi: gluPickMatrix(X, viewPort[3]-Y, 2.0, 2.0, @viewPort); so the small viewport is limited to 2x2 square. I add that i did everything due to the OpenGl tutorial so I am really confused. Hope someone could help me? [Edited by - panda_ on June 15, 2006 8:55:54 PM]

Share this post


Link to post
Share on other sites
Advertisement
Selection mode doesn't give you "what's on top of the color buffer" -- it gives you a list of all things that would have been drawn.

I'm not sure what the second question is.

Share this post


Link to post
Share on other sites
Your selection buffer contains one record for each entity that intersects your frustum. You have to parse the buffer to determine which one lies on top, since these records have the same order you passed them to GL.

The selection buffer's structure should be:

<n1: #names at hit#1>; <min z>; <max z>; name stack for hit#1: n1 x <name>;
<n2: #names at hit#2>; <min z>; <max z>; name stack for hit#2: n2 x <name>;
etc...

Wether z [min..max] is [0..2^31] or [2^31..0] depends on your glDepthRange()

Share this post


Link to post
Share on other sites
Welcome back :D

I am not sure if I get the idea of the picking mode right. For me 'gluPickMatrix' function should determine the area of volume that I am really interested in? Correct me if I am wrong.
In my opinion in picking mode we just have to inititialize the name stack and select buffer, run 'glPickMatrix' and name our objects (we may do this also in render mode, cause in this case function like 'glLoadName', 'glPushName' are ignored). Does it matter if we don't change the frustum??

Share this post


Link to post
Share on other sites
gluPickMatrix() creates a projection matrix and thereby defines a frustum (= volume of interest)...

...still not really sure if I understood your question

Share this post


Link to post
Share on other sites
Thanks for replies zimerman. I succeded in picking objects and now I get only one hit every time when I click the object of interest. But there is a problem with picking some objects. I can't select them though they are loaded with the 'glLoadName()' function and dimensions of new viewport defined by 'glPickMatrix' stay the same. Some objects mainly lines don't react to selection if I click them near the end of these lines. I suspect that the problem is bacause of the different projection matrix in the picking mode than in render mode and it's strange to me becaue the rendering function is the same in both cases excluding some unnecessary calls.
Please, help!

Share this post


Link to post
Share on other sites
I had a similar problem, theres a few things to note.

as you mentioned the y coordinate needs to be corrected in gluPickmatrix with viewport[3]-y.

it could be an aspect ratio problem, make sure the aspect ratio value is a double and not an int or it will round up/down.

make sure the fov and znear/far values match what you use normally.

a way to debug it is to first comment out the glrendermode(gl_select) line, then comment out the glupickmatrix function, this will prevent it from zooming in when it draws, then after your own draw function is called, add a Sleep(1000); so you can see what exactly its drawing, if it doesnt match what you see normally, then it could be one of the above reasons.

one thing i noticed that was kinda strange is that when i bind a vertex shader (cg) it adds a hit to the stack (the name pushed to initialize the name stack), when i turn it off i dont get a hit for the first initialized name. anyone else experienced this?

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!