PDA

View Full Version : glPushName vs glLoadName



David Doria
11-08-2008, 06:20 AM
if i use

glPushName(i);
DrawTriangle();
glPopName();

the picking works as i expect it to

I thought you can also use

glLoadName(i)
DrawTriangle();

but when I do that, the picking doesn't work.

Can someone explain the difference between these?

Thanks,
Dave

zeoverlord
11-08-2008, 07:06 AM
Load doesn not equal push, So in the two cases your not doing the same thing, you also have a pop in there, i think that might be significant.
Look it up on the reference pages (http://www.opengl.org/sdk/docs/man/)

The difference between the two.
push - Specifies a name that will be pushed onto the name stack.
load - Specifies a name that will replace the top value on the name stack.

David Doria
11-08-2008, 07:09 AM
clearly it is not doing the same thing... as indicated by not writing the same code, and by the different results...

I did look it up - clearly I am not quite understanding the name stack. If I push the name "1" onto the stack, draw something, and then pop it off, that something got drawn with name "1". If I "load" the name "1" onto the stack and then draw something, it sounds to me like that something should also be drawn with the name "1". How is this not correct?

zeoverlord
11-08-2008, 07:43 AM
yes if that's all your doing then it should work.

David Doria
11-08-2008, 07:54 AM
I see, I had to push SOMETHING onto the stack first, because glLoadName() replaces the top item on the stack, so if the stack is empty an error occurs.

Ie.



glPushName(1); //or any junk value

glLoadName(1);
DrawTriangle();

glLoadName(2)
DrawSomethingElse();

sammie381
11-08-2008, 12:35 PM
I see, I had to push SOMETHING onto the stack first, because glLoadName() replaces the top item on the stack, so if the stack is empty an error occurs.



This outline works for me:



// clear it
glInitNames();

// make it 'not empty'
glPushName(0);

// rendering loop starts here
{
glLoadName(whatever_id);
// draw here (begin,end)
}