Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Mouse selection

  1. #1
    Intern Newbie
    Join Date
    Dec 2011
    Posts
    46

    Mouse selection

    Hi,

    I would need that when I click somewhere on my render, my program could know where I clicked (more or less), let's say a kind of selection

    I tried to read and understand at the best this

    http://www.opengl.org/resources/faq/...n.htm#sele0020

    Basically there are three options:

    - selection render mode

    - render each primitive in an unique color

    - generate a pick ray


    I opened this 3d to ask you guys, since that page has some years, if all of them are still valid, or there is a new method that is not listed there

  2. #2
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302

    Re: Mouse selection

    Quick answer:
    Use the rendering in a unique color technique.


    Longer answer:
    I wouldn't use the old selection methods of OpenGL anymore. It isn' available on all plattforms (MacOS with a 3.2 context, OpenGL ES if you want to port to that), it isn't so widely used so I don't think the performance of this has a high priority for driver devs (might be wrong).

    Rendering everything in a unique color, read one pixel from the backbuffer, clear the buffer, render your scene normally (so you will never see the colored picking buffer on screen) works very well. You can also do this in a FBO in a lower resolution if you like etc. Quite flexible but also simple solution.

    Ray casting involves implementing ray casting ;-) A lot of work and probably slower (there might be special cases where this is a good idea).

  3. #3
    Intern Newbie
    Join Date
    Dec 2011
    Posts
    46

    Re: Mouse selection

    Quote Originally Posted by menzel
    Quick answer:
    Use the rendering in a unique color technique.


    Longer answer:
    I wouldn't use the old selection methods of OpenGL anymore. It isn' available on all plattforms (MacOS with a 3.2 context, OpenGL ES if you want to port to that), it isn't so widely used so I don't think the performance of this has a high priority for driver devs (might be wrong).

    Rendering everything in a unique color, read one pixel from the backbuffer, clear the buffer, render your scene normally (so you will never see the colored picking buffer on screen) works very well. You can also do this in a FBO in a lower resolution if you like etc. Quite flexible but also simple solution.

    Ray casting involves implementing ray casting ;-) A lot of work and probably slower (there might be special cases where this is a good idea).
    Hi Menzel,

    thanks for your answer..

    Actually I was discarding the unique-color option because I thought something different from what you explained me.

    Your suggest looks interesting, but maybe there is a problem: if I am using VBOs is that still possible?

  4. #4
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302

    Re: Mouse selection

    It doesn't matter how you draw your models as long as you can color each individually.

    That can be done with an alternative attribute for per-vertex colors (has the downside of a lot of redundancy) or better just as a uniform in a special fragment shader that just sets each fragment to the given color value. The underlying geometry is irrelevant.

  5. #5
    Intern Newbie
    Join Date
    Dec 2011
    Posts
    46

    Re: Mouse selection

    Quote Originally Posted by menzel
    It doesn't matter how you draw your models as long as you can color each individually.

    That can be done with an alternative attribute for per-vertex colors (has the downside of a lot of redundancy) or better just as a uniform in a special fragment shader that just sets each fragment to the given color value. The underlying geometry is irrelevant.
    1) the limit of primitives (or triangles) is 2^(8+8+8) = 16777216?

    2) shall I use really use shader? Because I still dont know how to use them

  6. #6
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302

    Re: Mouse selection

    1) The limit ob individual objects you want to pick is 2^(8+8+8+8) for 8bit RGBA render targets. If you want to select objects and not individual triangles, that should be sufficient. You can also use render targets with 32bit per channel and multiple render targets if you use shaders... You will run out of memory for your geometry before the 'picking-space' gets too small.

    2) You don't have to use them. Depending on what you also want to do, you might run into limitations of the fixed function pipeline later on...

  7. #7
    Intern Newbie
    Join Date
    Dec 2011
    Posts
    46

    Re: Mouse selection

    Quote Originally Posted by menzel
    1) The limit ob individual objects you want to pick is 2^(8+8+8+8) for 8bit RGBA render targets. If you want to select objects and not individual triangles, that should be sufficient. You can also use render targets with 32bit per channel and multiple render targets if you use shaders... You will run out of memory for your geometry before the 'picking-space' gets too small.

    2) You don't have to use them. Depending on what you also want to do, you might run into limitations of the fixed function pipeline later on...
    Unfortunately I need to select individual triangles... how could I do?

  8. #8
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302

    Re: Mouse selection

    You can set an individual color per triangle, either with the fixed-function pipeline, an extra attribute or even rerive a color in the shaders from gl_PrimitiveID. It depends on how you want to draw your stuff and whether you want to use shaders.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •