glPushName vs glLoadName

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

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

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.

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?

yes if that’s all your doing then it should work.

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();


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)
 }