I am creating a simple 2D OpenGL game, and I need to know when the player clicks or mouses over an OpenGL primitive. (For example, on a GL_QUADS that serves as one of the tiles…) There doesn’t seems to be a simple way to do this beyond brute force or opengl.org’s suggestion of using a unique color for every one of my primitives, which seems a little hacky. Am I missing something? Thanks…
Share
You can use OpenGL’s
glRenderMode(GL_SELECT)mode. Here is some code that uses it, and it should be easy to follow (look for the_pickmethod)(and here’s the same code using
GL_SELECTin C)(There have been cases – in the past – of
GL_SELECTbeing deliberately slowed down on ‘non-workstation’ cards in order to discourage CAD and modeling users from buying consumer 3D cards; that ought to be a bad habit of the past that ATI and NVidia have grown out of 😉 )