View Full Version : How can I detect a surface on 3Dobject by mouse click?

01-24-2002, 06:13 AM
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...

01-25-2002, 12:56 AM
Hi !

You use selection mode, something like this:
glSelectBuffer( ...);
glRenderMode( GL_SELECT);
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.