tags:

views:

318

answers:

3

What's the meaning of doing that in OpenGL?

Does that reset all the names?

+3  A: 

http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/pushname.html

It's used to push a new name onto the name stack (primarily used for mouse picking functionality). It will not clear the names, and you can go back to the previously set name by using glPopName.

EDIT: Out of curiosity, what are you using this for? That's a pretty old API, and I think it's been deprecated in OpenGL 3.0. If you're trying to do anything other than mouse picking then you may be using the wrong functions.

Toji
A: 

Yes, I want to use it for mouse picking,

What functions should I use?

In the last topic, I wasn't so clear and I did not post that I would like to know the meaning of glPushName( -1 )

What does that do?

A "name" in OpenGL is nothing but an integer who's meaning you decide. may people use defines or enums but it's all just ints in the end. In this case, -1 is really no different than 1, 5, or 42. It's just another number. In most examples I've seen that use -1, it seems to be set to encapsulate "non selectable" geometry or to indicate the last item in the stack. As such, I believe that -1 has no special meaning other than what you choose to assign to it.
Toji
unsually names are GLuints which means unsigned ints, so -1 isn't that smart.usually you initialize the namestack like this:glRenderMode(GL_SELECT);glInitNames();glPushName(0); //you can't do anything with a empty namesatack except error handling :>//draw your primitives with glLoadName(primitive_name); aheadGLint hits(glRenderMode(GL_RENDER);//returns the number of hits
penguinpower
+3  A: 

glPushName() pushes new 'names' on the name stack when the current render mode is GL_SELECT. It was a crude API scheme to associate primitives (triangles, quads, triangle strips) with identifiers to be used for selection. As Toji said, these calls and associated state is deprecated in OpenGL 3.x, and unsupported when the GL_ARB_compatibility extension is absent. It wasn't really usable in the first place, since the minimum limit of supported names was only 64. If you need to "choose objects with the cursor", you should rather use color picking. Color picking is a technique where you render different primitives with different colors, and then read the color at the cursor position back. This can be done easily with gluPickMatrix() and glReadPixels(). Make sure only solid colors are rendered, which means no shading, lighting or texturing, and that dithering is disabled. Disable with glDisable(GL_DITHER)

Mads Elvheim
Your suggestion about using color-based picking is a good one, but your statement about the minimum name limit being 64 is probably not accurate. The "Redbook" (version 2), pg. 565 describes a minimum support for 64 names in the "name stack". This represents the number of different names that a *single* object can have, and has nothing to do with the number of different objects that can be uniquely named.
nobar