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

Thread: Line stipples, Selection and Picking: How to do these in GL 4.3?

  1. #1
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76

    Line stipples, Selection and Picking: How to do these in GL 4.3?

    Greetings:
    I am trying to rework some pre-shader programs in GL 4.3 core profile. Questions I have run into:

    1. How to draw stippled lines? As there's no glEnable(GL_LINE STIPPLE) or glLineStipple() in 4.3.

    2. How to do selection and picking? E.g., to pick the object clicked by the mouse. My pre-shader program uses gluPickMatrix() to generate the frustum centered at the clicked pixel (I believe gluPickMatrix() is still available though I haven't checked) and then glRenderMode(GL_SELECT) etc.

    However, there is no glRenderMode() in 4.3.

    Thanks in advance for your help.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    1: Implement the same logic as glLineStipple in a fragment shader and use discard.
    2: Ray-casting - for my taste at least.

  3. #3
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by sam_thedancer View Post
    2. How to do selection and picking? E.g., to pick the object clicked by the mouse. My pre-shader program uses gluPickMatrix() to generate the frustum centered at the clicked pixel (I believe gluPickMatrix() is still available though I haven't checked) and then glRenderMode(GL_SELECT) etc.
    GLU in general is deprecated, and the OpenGL functionality on which gluPickMatrix() depends (OpenGL matrix functions) isn't present in the 3+ core profile. You would need to generate the picking matrix yourself then multiply it with the projection matrix which you pass to the shader.

    The closest thing available to glRenderMode() in 3+ core profile is transform-feedback mode, but that's closer to GL_FEEDBACK than GL_SELECTION (and it returns the data prior to clipping/culling).

    For picking, one option (among many) is to render the scene into a single-channel integer FBO, with object IDs in place of colours. An advantage of a raster-based approach is that it works with objects which use alpha and/or stencil tests.

  4. #4
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    Thanks a lot for the suggestions.

    I indeed got line stipple working reading gl_FragCoord. x and y, and discarding according to the stipple pattern.

    This got me thinking about picking and I would ask your opinion if the following might work. Read
    the pixel coords from the mouse click, then render the objects one by one and read gl_FragCoord.z if gl_FragCoord.xy match the pixel coords. Least z is picked.

    Do you think this will work? Appreciate your opinion before I try to code. Thanks again.

    Added: Just thought of a potential problem. In the first phase, when the z competition takes place and color mask is off, the fragment shader has to record the id of the winning object in a variable that can be accessed by the application program in the second drawing phase. How to do this?
    Last edited by sam_thedancer; 09-03-2013 at 02:03 AM.

  5. #5
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by sam_thedancer View Post
    Added: Just thought of a potential problem. In the first phase, when the z competition takes place and color mask is off, the fragment shader has to record the id of the winning object in a variable that can be accessed by the application program in the second drawing phase. How to do this?
    Store the object ID in the framebuffer (and use the built-in depth comparison). There are other options (e.g. buffer variables, images), but writing to the framebuffer is the fastest.

Posting Permissions

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