Hello All,
Getting along pretty well with this OpenGL stuff but have hit a rock wall with picking. I am using the GL_SELECT mode and i have it somewhat working but it’s hit-and-miss!(I am using Python and the Togl (Tcl OpenGL widget) for display)
Here is my Pick method which is an event handler for <Control-Button-1> events. Note in Python comments start with a hash #
def onPick(self, event):
x, y = event.x, event.y
buff = glSelectBuffer(64)
glRenderMode(GL_SELECT)
glInitNames()
glPushName(-1)
view = glGetIntegerv(GL_VIEWPORT)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
realy = list(view)[3]-y
print x, realy
gluPickMatrix(x, realy, 1, 1, view)
#gluPerspective(30, 1.0, 0.0001, 1000.0)
glMatrixMode(GL_MODELVIEW)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
for e in self.entities:
glLoadName(e._pickname)
e._draw()
#self.tk.call(self.togl, 'swapbuffers')
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
hits = glRenderMode(GL_RENDER)
print 'hits=',hits
This code actually works but it’s not selecting the correct faces (well not all the time). I commented out the glRenderMode(GL_SELECT)
line and swapped the buffer so i could “see” the pick box but it’s no where to be found? (Yes i did increase the size to 5x5) I think something is wrong with my projection matrix and the gluPickMatrix is getting fowled up because of it.
Q1: Should i be setting the Projection matrix, and if so, should i do it before or after the call to gluPickMatrix?
Thanks for any and all suggestions!