I have implemented picking using the selection buffer by constructing my
list of names for my objects with glPushName(index) and glPopName() and
making a call to glSelectWithCallback(...) when the user clicks on the
window. This works perfectly when I am rendering a scene with a single
viewport in my OpenGL window.
But, ..... I have an pyOpenGL app that renders a scene with four viewports
(much like the default view in Maya, 3D studio max, etc.) like so:
------------------------
| A | B |
------------------------
| C | D |
------------------------
While debugging, I set each viewport to render the same scene from the same
camera angle. Picking only works in the "A" viewport, and I only register
hits from the viewport that was rendered last.
I draw each viewport by doing the following:
###### START SNIP #########
if (view==0):
glViewport (0, window_height/2, window_width/2,
window_height/2);
glMatrixMode (GL_PROJECTION); # // Select The Projection
Matrix
glLoadIdentity (); # // Reset The Projection Matrix
# // Set Up Perspective Mode To Fit 1/4 The Screen (Size Of
A Viewport)
gluPerspective( 45.0, float(self.windowSize[0]/2.0) / float(
self.windowSize[1]/2.0), 0.1, 500.0 );
# Select The Modelview Matrix
glMatrixMode(GL_MODELVIEW);
# Reset The Modelview Matrix
glLoadIdentity();
# Clear the Depth Buffer
glClear(GL_DEPTH_BUFFER_BIT);
self._DrawGLScene()
######################################
# Top right: negative y-axis
if (view==1):
glViewport (window_width/2, window_height/2, window_width/2,
window_height/2);
glMatrixMode (GL_PROJECTION); # // Select The Projection
Matrix
glLoadIdentity (); # // Reset The Projection Matrix
# // Set Up Perspective Mode To Fit 1/4 The Screen (Size Of
A Viewport)
gluPerspective( 45.0, float(self.windowSize[0]/2.0) / float(
self.windowSize[1]/2.0), 0.1, 500.0 )
# Select The Modelview Matrix
glMatrixMode(GL_MODELVIEW);
# Reset The Modelview Matrix
glLoadIdentity();
# Clear the Depth Buffer
glClear(GL_DEPTH_BUFFER_BIT);
self._DrawGLScene()
...
...
# since this is double buffered, swap the buffers to display what
just got drawn.
glutSwapBuffers()
###### END SNIP #########
I implement picking by making a call to glSelectWithCallback(...) following
the logic from example code posted at the first link from the google search
results titled "3-D programming with python" from:
http://www.google.com/search?hl=en&client=firefox-a&rls=com.ubuntu%3Aen-US%3Aofficial&hs=HzU&q=%223-D+programming+with+python%22+site%3Aacm.org&btnG=Search
(note: I think you might need an ACM subscription to access the example
source code posted in the above link that I used as a basis for my own code)
If it helps, I'm running python 2.5 in Ubuntu 7.04 with all the default
packages taken from synaptic (i.e. i did not compile pyopengl or anything
myself).
Let me know if you have any ideas.
Thanks!
Pete
|