Jump to content
  • Advertisement
Sign in to follow this  

OpenGL picking opengl + python not working

This topic is 3503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm trying to implement selection in opengl through pyopengl, but it's not working I don't know why, but there is no glSelectWithCallback method in my python (2.6) I believe It became deprecated. Anyway, I googled it and I found this selection code:
    def glSelectWithCallback(x, y, callback, xsize = 5, ysize = 5, buffer_size = 512):
        '''glSelectWithCallback(int x, int y, Callable callback, int xsize=5, int ysize=5)
      x,y -- x and y window coordinates for the center of the pick box
      rendercallback -- callback (callable Python object) taking 0 arguments
        which performs pick-mode rendering
      xsize,ysize -- x and y dimensions of the pick box (default = 5x5)
    The function returns a tuple (possibly empty) of:
      ( (minimumzdepth, maximumzdepth, (name, name, name),...)
        minimumzdepth, maximumzdepth -- depths in integer format
          If you want the more traditional 0.0 to 1.0 numbers, divide
          by (2**32)-1
          If you want the physical depth, multiply that by the frustrum depth and
            add your near clipping plane.
        name -- the names (integers) used in calls to glPushName( int )'''
        # this import needs to be late binding or Python gets stuck in an infinite import loop   
        from OpenGL.GLU import gluPickMatrix
        viewport = glGetIntegerv(GL_VIEWPORT)
        previousviewmatrix = glGetDoublev(GL_PROJECTION_MATRIX)
        gluPickMatrix(x, viewport[3] - y, xsize, ysize, viewport)
        return glRenderMode(GL_RENDER)
However, in order to succeed, I'm registering the names in the stack before drawing it, look:
        def paintObjects(self) :
            glRotatef    (self.rotx, 1,0,0);
            glRotatef    (self.roty, 0,1,0);
            for i in range(0,len(self.objects)):
                if (self.wire):

I have a list of objects, every time I paint them I push / draw / pop. However, when I try to get the hits list, It comes empty. I'm calling it this way:
    def mouseReleaseEvent(self,ev):
            self.select(ev.pos().x(), ev.pos().y())

    def select(self,x,y):
            result = glSelectWithCallback(x,y, self.paintObjects)
            print str(result)

I don't what is wrong with this... I read almost all available tutorials from google search (ok. Not possible)... Does anyone know what's going on here? Please, help me, I'm trying to do it since my last 5 days, thanks a lot [Edited by - sfelixjr on May 4, 2009 5:14:38 PM]

Share this post

Link to post
Share on other sites
If the push / draw / pop operations are performed while in the modelview matrix mode, try inserting glMatrixMode(GL_MODELVIEW) before the callback() and before the return statements in the glSelectWithCallback routine. This will ensure the glRotatef() statements in your paintObjects routine are applied to the modelview matrix and not the projection matrix.

[Edited by - gedesch on May 9, 2009 12:51:47 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!