selecting object drawn on graphics window in OpenGL??

Discussion in 'Mac Programming' started by kashmoney2006, Apr 23, 2008.

  1. kashmoney2006 macrumors regular

    Dec 12, 2007
    I was wondering if there is a way to select an object that I draw in a graphics window? say for example, I have 3 spheres drawn to the window, is there a way to select one of them using the mouse and differentiate it from he other 2? the only way I know of is by comparing the objects position and the position of the mouse. Is there an easier way? All ideas are welcome.
  2. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK
    OpenGl does have a mechanism called Picking to do this. But it's easy to implement your own method. For example when a mouse is clicked. Draw the scene again to the back buffer (no need to display it), but use a different colour for each sphere. You can then identify the sphere clicked on by reading the colour of the pixel that was clicked on.

    b e n
  3. kashmoney2006 thread starter macrumors regular

    Dec 12, 2007
    thanks, ill look up picking on google. and that color trick doesnt seem too hard either. except it may get tedious to keep track of all the colors as the window will have many spheres in it.
  4. kpua macrumors 6502

    Jul 25, 2006
    The OpenGL picking is really easy to do. A quick reference to the man pages for glRenderMode and gluPickMatrix should get you going pretty quick.
  5. kashmoney2006 thread starter macrumors regular

    Dec 12, 2007
    I got it to work, but not after translating the objects. anyway to translate the pick matrix the same amount as you translate the drawn objects when using glTranslate? ive tried different things but none havent worked for myself.

    Edit: nevermind. I got it to work. :)

Share This Page