Selection, picking with PyOpenGL?

Mike C. Fletcher mcfletch at rogers.com
Sat Jul 30 09:45:59 EDT 2005


Erik Max Francis wrote:

>I was interesting in adding selection and hit testing to ZOE, and was 
>looking at the PyOpenGL wrappers' handling of selection and picking.  I 
>see glSelectBuffer to specify the size of the buffer, and glRenderMode 
>properly returns the number of hits when put back into GL_RENDER mode, 
>but I don't see any way within PyOpenGL itself to access the select 
>buffer to actually process the hits.  Is there any way to do this 
>without using OpenGLContext?  (If not, does this make sense, given that 
>OpenGLContext is supposed to be an additional helper library for a 
>gentle introduction to OpenGL?)
>  
>
I think you're missing what's returned from the glRenderMode code (which 
is non-standard OpenGL, to avoid the need for Python code using and 
decoding structured pointers), from OpenGLContext:

                nameStack = list(glRenderMode(GL_RENDER))

that is, you get a stack of name records (i.e. your glSelectBuffer with 
(near,far,names) records) back from the glRenderMode call, *not* just a 
count of the records produced.

In general, you shouldn't *need* OpenGLContext to do anything, as all of 
its OpenGL code is written directly in Python to PyOpenGL's API (that 
was its original purpose in life, to test those APIs).  It is, however, 
intended to provide a source for sample code showing how to accomplish 
effects when using PyOpenGL, so from renderpass.py:

                    event.setObjectPaths([
                        nodepath.NodePath(filter(None,[
                            self.selectable.get(name)
                            for name in names
                        ]))
                        for (near,far,names) in nameStack
                    ])

shows you how to deal with the glSelectBuffer result, namely that it's a 
near value, a far value, and a set of integer names (the name stack) for 
each record in the set.  OpenGLContext is here creating a node-path of 
all selectable objects from the scenegraph root to the final selected 
object using the nameStack and a registered set of name:node values 
(self.selectable).  It will use those to populate the event objects that 
show up in the OpenGLContext mouse-event-handling APIs.

HTH,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com




More information about the Python-list mailing list