Results 1 to 4 of 4

Thread: Picking In OpenGL

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    10

    Question Picking In OpenGL

    I have followed several tuts about picking and i have gotten the basics figured out, however i have come across a strange issue... My picking seems to stop working randomly. I'll click directly on a vertex i want to select and it will come back with 0 hits.

    I tried upping my picking tolerance to 30 which seemed rather high and it still has issues.

    Here is the relevant snippet, if anyone could point out any obvious bugs i'd appreciate it!

    pastebin.com/7tsuiBY0

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214
    You probably didn't specify a select buffer. Where did you say that your PickBuffer shoud be the actual GL SelectBuffe?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    10
    Oh sorry, that is done in the initialize function.

    Picking does work, just not all the time. Sometimes i click a vertex and it puts -1 and the number of the vertex in the buffer, other times i click a vertex dead on and it doesn't detect any hits. :/

  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214
    Then the problem is somewhere else. Ensure that you are drawing the same scene in both GL_RENDER and GL_SELECT modes (it seems it is not the case). Also ensure GL context is active in the tread you where you call pick() function.

    I suggest to use the following pattern:
    Code :
     
    PickObject(...,int x, int y)
    {
        GLint viewport[4];
        GLuint selectBuf[512];
     
        glSelectBuffer(512,selectBuf);
        glRenderMode(GL_SELECT);
     
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
     
        glGetIntegerv(GL_VIEWPORT, viewport);
        gluPickMatrix(x, viewport[3]-y, 3, 3, viewport); // 3 pix is enough
        gluPerspective(...); // the same as in reshape function or wherever set up
     
        glMatrixMode(GL_MODELVIEW);
        glInitNames();
        glPushName(0); // useful only if you are using glLoadName()
     
        Draw(GL_SELECT);
     
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
        glFlush();
     
        int hits = glRenderMode(GL_RENDER);
        unsigned int retVal = 0;
        if(hits != 0) 
            retVal = Proces****s(hits,selectBuf);
     
         return retVal;
    }

    For all details look at Legacy OpenGL Programming Guide Chapter 13 - Selection and Feedback.

Similar Threads

  1. Picking with Opengl
    By TimLipp in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-08-2011, 01:43 PM
  2. Ray picking in OpenGL ES 2
    By MaximV in forum OpenGL: General
    Replies: 3
    Last Post: 02-06-2010, 06:46 AM
  3. Z-buffer picking, gluUnProject picking not working
    By Icetigris in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-29-2008, 10:38 AM
  4. Picking in OpenGL
    By Jan Stalmach in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 02-18-2008, 06:15 AM
  5. OpenGL Picking help
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-31-2004, 08:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean