PDA

View Full Version : selection



Hylke Donker
07-29-2005, 06:16 AM
Hello,
I would like to use selection for picking.
As I understand, every geometric primitive which is in the viewing volume, causes a hit right?
If you have a couple of triangles, which are only one name, they only cause one hit.
My OpenGL redbook says this about glLoadname:

Replaces the value at the top of the name stack with name.[..]So glLoadName(blaat); would equal to:

glPopName();
glPushName(blaat);But here's the thing I don't understand.
All my code examples of my book look like this:

glLoadName(x);
drawsomething();
glLoadName(x+1);
drawsomething2();
glLoadName(x+2);
drawsomething3();
[..]But doesn't that *delete* the last value in the stack and then add a new one to it?
So if I understand it right, it would lost all information about the geometric primitives except for the last(because the stack contains only one thing)(which is not the case).
IMHO it would be more logical that it would look like this:

glPushName(x);
drawsomething();
glPushName(x+1);
drawsomething2();
glPushName(x+2);
drawsomething3();
[..]What's wrong with my way of thinking?
Thanx Hylke

mikael_aronsson
07-29-2005, 07:29 AM
Hi !

You have to remember that all selection is done while it is "rendered" so if you use glLoadName you will get the hit that was active when the object is selected, if you use glPushName you will get all hits that are pushed for each hit instead.

Mikael

Hylke Donker
07-30-2005, 12:39 AM
Ok, thanx.
But I only don't understand about the glPushName().
Could you try to explain it more easyer?
Thanx Hylke

Overmind
07-30-2005, 01:18 AM
For every hit, you get the whole content of the name stack at the time when the hit occurs.

glLoadName(1); // stack = 1
draw();
glLoadName(2); // stack = 2
draw();
glLoadName(3); // stack = 3
draw();

Assuming every draw function produces a hit, you will get 3 hits:
1
2
3

glPushName(1); // stack = 1
draw();
glPushName(2); // stack = 1 2
draw();
glPushName(3); // stack = 1 2 3
draw();

Now you'll get these 3 hits:
1
1 2
1 2 3

Hylke Donker
07-30-2005, 01:46 AM
Ok thanx, I think I finally understand it now.
Hyke