Selection, picking with PyOpenGL?

E

Erik Max Francis

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?)
 
M

Mike C. Fletcher

Erik said:
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
 
E

Erik Max Francis

Mike said:
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:

I was indeed. I was looking at the text description, which, like the
OpenGL documentation, talks about it returning the number of hits. I
didn't look carefully enough at the Python return value :).

Thanks, Mike!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,311
Members
47,981
Latest member
satome

Latest Threads

Top