[PyOpenGL-Users] Picking using SelectBuffer
Brought to you by:
mcfletch
From: Simon W. <sim...@gm...> - 2005-07-31 03:14:27
|
I'm trying to use glRenderMode(GL_SELECT) to implement picking. The problem is, almost all picking examples deal with 3D projection (gluPerspective), whereas I am using glOrtho, so I suspect I need to do something different. The below code doesn't work, it accumulates hits in the select buffer, but they are not the hits I expect. Any pointers on where I might be going wrong? Also, is there a simple way to get OpenGL to render a small box on the screen which shows exactly which region is being picked? Thanks for any help...=20 Sw. def pick(self, position): glInitNames() glSelectBuffer(64) glRenderMode(GL_SELECT) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() viewport =3D glGetIntegerv(GL_VIEWPORT) n_w,n_h =3D display._screen.dimensions glOrtho(-n_w,n_w,-n_h,n_h,1,0) gluPickMatrix(position[0],viewport[3]-position[1],3,3,viewport) glMatrixMode(GL_MODELVIEW) for index, i in enumerate(self.items): glPushName(index) display._screen.blit(i.item, i.position) glPopName() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glFlush() =20 items =3D [] for hit in glRenderMode(GL_RENDER): items =3D items + [self.items[i] for i in hit[2]] return items |