glLoadName trouble

i have 4 objects and i am trying to glLoadName each one with a different name. However the first three objects all get called ‘2’ and the last one gets called ‘1’ instead of 1,2,3 and 4 like i think should happen. whats wrong? thanks

object_count=4;
m=0;

static void display (void)
{
//Init names of objects
glInitNames();
glPushName(m);

draw();
. . . .
. . . .
. . . .
}

void draw()
{
int obj; // object counter

//////////////////////////////
// draw all the objects 
for (obj = 0; obj < object_count; obj++) {

	glPushMatrix();
			
		glLoadName(m+1);
		drawPolygon();
		m++;
	glPopMatrix();
}

}

The only OpenGL functions you have here are glPushMatrix and glPopMatrix. I simply don’t know what the rest is, but I know they don’t belong to OpenGL. It’s bad practice to prefix your own stuff with gl, it only confuses people.

Huh? Duh? All the calls posted that start with gl are valid calls. They are a part of the standard code used for picking. Check your OpenGL docs again.

Originally posted by zeckensack:
The only OpenGL functions you have here are glPushMatrix and glPopMatrix. I simply don’t know what the rest is, but I know they don’t belong to OpenGL. It’s bad practice to prefix your own stuff with gl, it only confuses people.

well anyway…anyone have any thoughts about my picking dilema?

That’s a weird one. Your code seems flawless. Are you sure your are not calling glLoadName somewhere in your drawPolygon() function?

Originally posted by gussy:
i have 4 objects and i am trying to glLoadName each one with a different name. However the first three objects all get called ‘2’ and the last one gets called ‘1’ instead of 1,2,3 and 4 like i think should happen. whats wrong? thanks

[Edit] Note that you only init m once. Thus after the first display m = 4. However since it isn’t reinitialised your next display should end up with names starting from 5 and ending with eight 8; and keep incrementing each display.

[This message has been edited by Furrage (edited 04-04-2002).]

[Edit] Post your code to process your hits as well. The problem could be there.

[This message has been edited by Furrage (edited 04-04-2002).]

Oops, sorry. I guess you never stop learning