problem on picking

I’m using gluPickMatrix to determine which object in the window is picked.

However, I’m having the problem that… the last object that is rendered … and assigned a name ( using glPushName(2) )… is also associated with the rest of the space in the window without any objects. So even if I am click on blank space in the window, it returns the name/id of the last object I rendered.

Any suggestion what may be causing this? I’m also using glPopname with glPushname

thanks!

Ideas:
-Make sure the gluPickMatrix is at the right place in the code and in the correct origin layout.
-Draw the area with the PickMatrix in GL_RENDER mode to see if you picked the right place.
-Don’t exceed the name stack size.
-Does the pickline.exe sample from the RedBook work? It doesn’t use PushName and PopName, instead reloads the top of stack with LoadName. This is how I did it in the past and it always worked.

Thanks for the reply!

– The gluPickMatrix seems to be in the right place. After that, I call a procedure that draws the objects ( which calls other procedures… dunno if it affects the stack).

– it is in GL_RENDER mode and the I’m only pushing 2-3 names in the names stack. So I don’t think it’ll overflow.

– I’ve tried it with LoadName and it gives the same result.

I’m still having trouble… that the other space of the window is identified along with the last object rendered on view. For example, Object 1 & 2 can still be identified but when I click on a blank space in the window, it also identifies object 2

When I used picking, I had one gl name that I reserved as an invalid name (indicating no object). When I began issuing drawing commands for an object, I would push it’s name onto the stack. Immediately after the last drawing command for the object, I would replace the name on the stack with the invalid name. This way, I was certain that no extra drawing commands were included as part of the object.

It almost sounds like a glClear(GL_COLOR_BUFFER_BIT) is getting included as part of your last object.

Myabe you did something more after rendering object2. You have to empty name stack(by popping everything) after drawing the last object or all other objects drawn after the object will be “identified” as object2.

And, just in case, don’t forget that the origin of OpenGL viewport is at lower-bottom corner. So y-coordinate is REVERSED from GDI coordinate! OpenGL viewport y-coordinate increases UPWARD, whereas GDI’s downward.

And I recommend using glLoadName() instead of glPushName() if the objects are two distinctive ones. glPushName() is used to identify part of hierachical objects.

Myabe you did something more after rendering object2. You have to empty name stack(by popping everything) after drawing the last object or all other objects drawn after the object will be “identified” as object2.

And, just in case, don’t forget that the origin of OpenGL viewport is at lower-bottom corner. So y-coordinate is REVERSED from GDI coordinate! OpenGL viewport y-coordinate increases UPWARD, whereas GDI’s downward.

And I recommend using glLoadName() instead of glPushName() if the objects are two distinctive ones. glPushName() is used to identify part of hierachical objects.