I can already find the world coordinates of the place I clicked on and also checks this with the depth buffer. To do this, use the following code:
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX,winY;
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
GLfloat z_cursor;
winX = (float)x_cursor;
winY = (float)viewport[3]-(float)y_cursor;
glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z_cursor);
GLdouble x, y, z;
gluUnProject(winX, winY, z_cursor, modelview, projection, viewport, &x, &y, &z);
where x_cursor and y_cursor are my cursor coordinates.
So far so good, and when you print x, y, z they seem good!
But now ... After parsing my files containing all the polygons / triangles. I put everything into OpenGL DISPLAY lists. So my program basically just calls lists and translates / rotates them. Each object has a unique name. So, all I hold is lists, I don't save points / triangles of every object
My question is:
So, I have my world coordinates where I clicked, but how can I figure out which object corresponds to this position !?