Interactive multi-selection with OpenGL

Hi.
I have worked in a scene where users can interacte thought the mouse.
By clicking, a “3D object” should me selected (just painted in other color) on the screen.
The problem is that sometimes OpenGL returns more than one object, so my question is how could select the “nearest” object on the screen ?!
Below some code I have done:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// selection buffer
GLuint buffer[128];
glSelectBuffer( 128, buffer );

// chance render mode
glRenderMode(GL_SELECT);

// switch to projection and save the matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix();

// get the viewport
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

// new clipping volume, a small
//square around mouse´s cursor
glLoadIdentity();
gluPickMatrix( pos.X(), viewport[3]-pos.Y(), 2, 2, viewport); // pos is a Point from mouse click



Render();

// collect the hits
GLint hits = glRenderMode(GL_RENDER);

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So, when “hits > 1” how can I get the nearest object selected ??!!
Thanks a lot in advance.
[ ]'s

Rogerio

>>so my question is how could select the “nearest” object on the screen ?!<<

check all the ‘selected’ objects and see which ones closest by
A/compare the object Boundingshapes, or if not good enuf, cast a ray from the into the scene on that point and find the closest triangle it intersects.
B/draw each triangl/object in a different color, read back the pixel under the mouse, see what color it is, u now know what is the closest triangle under the mouse (unless u have depth fighting or something)
*watch out turn off dithering, + in 16bit color youre limited to the number of different ‘objects’