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 4 of 4

Thread: OpengGL 4 + select

  1. #1
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2

    OpengGL 4 + select

    Hello,

    I'm new in this forum, and I'm starting with opengl4. My doubt is about object selection/moving.

    I read some documents about selecting objects in an scene (ray tracing, GL_SELECT, color picking, etc..)
    However, since GL_SELECT has been deprecated, which is the adequate method for selecting/moving objects in the scene? (assume a simple scenario with a simple cube).

    Thank you very much
    Alberich

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    (assume a simple scenario with a simple cube

    gluUnProject should work for this; I don't like it when the scene gets more complex.

  3. #3
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2
    I'm really sorry for the delay, I've been busy with exams.

    The gluUnproject is for color picking isn't it? (assuming simple scenes)
    When the scene get more complex, which method will you use?

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by alberich2k5 View Post
    The gluUnproject is for color picking isn't it?
    gluUnProject simply concatenates the matrices, inverts the result, then transforms the specified point. It's used for converting screen coordinates to object coordinates, e.g. if you're going to be performing picking in the application code. Or rather, it used to be; with modern OpenGL, you generate your own matrices, so there's no reason to get OpenGL involved.

    Quote Originally Posted by alberich2k5 View Post
    When the scene get more complex, which method will you use?
    The "modern" alternative to select and feedback modes is transform-feedback (which is more like feedback mode than select mode). This lets you capture the output after vertex and geometry shaders (and culling).

    The way to implement something like selection would be to add an integer vertex attribute for the object ID, have the vertex/geometry shader output this as a "flat" variable, and use transform-feedback to capture this variable. If you need hierarchical "names", you would need to implement this in the application, allocating integer IDs and storing the mapping from IDs to names.

    An alternative would be to add another colour buffer to which the object ID would be written, and use glReadPixels() to read a single pixel from the buffer to obtain the object ID under the cursor. This may be preferable if the window isn't being continually refreshed and you want to implement "mouseover". Programs using OpenGL 1.x often did something similar by rendering the scene with object IDs mapped to colours, but support for integer framebuffers makes this more robust (the colour approach would often fail on systems with limited colour depth).

Posting Permissions

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