Opengl Picking

Started by
1 comment, last by Spoons 20 years, 9 months ago
I have picking set up, using the tutorial on gametutorials.com. I render a simple set of quads, and assign one id to all of them (for ease). This is how I do it.

glInitNames();
glPushName(0);
glLoadName(100);
Then, I draw the vertices to assign them to that ID.

for(int y=0; y<MAP_SIZEY; y=y+2)
	{	
		for(int x=0; x<MAP_SIZEX; x=x+4)
		{
			this->TileTexID = this->Map[x>>4][y>>2];

			glBindTexture(GL_TEXTURE_2D, MapTexture.g_Texture[this->TileTexID]); 

			glBegin(GL_QUADS); 
			glTexCoord2f(0.0f, 1.0f); glVertex3f(float(x), float(y - 1), 0.0f); 
			glTexCoord2f(1.0f, 1.0f); glVertex3f(float(x + 2), float(y), 0.0f); 
			glTexCoord2f(1.0f, 0.0f); glVertex3f(float(x + 4), float(y - 1), 0.0f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(float(x + 2), float(y - 2), 0.0f); 
			glEnd();
		}
	}
Then...

glEnd(); // I call this again, to stop all drawing to the ID.

glPopName();
In my mouse function, I use the exact same function used in gametutorials, to return the id of the object that was clicked. I call it when the mouse button is pressed. What happens is, the function always returns zero, instead of the id I want. I am thinking it may have something to do with either the way I am drawing the tiles, or my camera function. Every frame, my camera calls gluLookat. I then change the variables of the position, when the user presses an arrow in a certain direction. Any help is greatly appreciated. Thanks
Advertisement
Try setting the pushname''s argument to 100 and see if that works. It never works for me if I don''t push the first name onto the stack whenever I start an opengl picking routine.

Resource IDs:
//~Object Selection IDs//The element specification screen#define SELECT_FIRE                     2001#define SELECT_WATER                    2002#define SELECT_EARTH                    2003#define SELECT_AIR                      2004


Actual Drawing Code:
	    glInitNames();	    glPushName(2001);	    glEnd();	    glLoadName(SELECT_FIRE); 	    glBegin(GL_LINES);	    glEnd();	    glPushMatrix();               Draw_Sphere(2, 0.0, 0.0, 0.0, 0.7, 35,-1.5, 1.0, -5);	    glPopMatrix();	    glEnd();	    glLoadName(SELECT_EARTH); 	    glBegin(GL_LINES);								    glEnd();	    glPushMatrix();	                   Draw_Sphere(5, 0.0, 0.0, 0.0, 0.7, 35,-1.5, -1.0, -5);	    glPopMatrix();	    glEnd();	    	    glLoadName(SELECT_AIR); 	    glBegin(GL_LINES);								    glEnd();	    glPushMatrix();                Draw_Sphere(4, 0.0, 0.0, 0.0, 0.7, 35,1.5, -1.0, -5);	    glPopMatrix();	    glEnd();	    glLoadName(SELECT_WATER);	    glBegin(GL_LINES);								    glEnd();	    glPushMatrix();                           Draw_Sphere(3, 0.0, 0.0, 0.0, 0.7, 35,1.5, 1.0, -5);	    glPopMatrix();	    glEnd();            glPopName();
Ok, thanks for the help, I got it working...

btw: I wouldn''t reveal too much of your contest entry,

This topic is closed to new replies.

Advertisement