How can I detect a surface on 3Dobject by mouse click?

I rendered a 3D object using OpenGL, e.g, a cube.
Is there any method to detect which surface on the cube I choose by mouse click?
thanks a lot…

Hi !

You use selection mode, something like this:
glSelectBuffer( …);
glRenderMode( GL_SELECT);
glInitNames();
glPushName( 0);

Then you render then scene again and before you render each face of the cube you use glLoadName( n); when n is a unique identifier, used to identify that surface.

You then switch back with:
glRenderMode( GL_RENDER);

And get the result which is a list of id values of things that where hit.

This is very oversimplified, you must also set the picking matrix and a few other things before it will work.

You can find more info in the FAQ on this website, for examples on selection you can have a peek at the demo examples included with Mesa or GLUT.

Mikael