I am using python with Qt from past 1 year.. now i have to use pyqt with opengl.
i am tring to write a sample program which can able to draw object ( eg cube,dot) and user can able to select using mouse.
but now i have done all the possible way to use opengl functions but still not able to select :(
I am using folowing code to pick :
can any one help me.. please give me any working simple program for selection
i am tring to write a sample program which can able to draw object ( eg cube,dot) and user can able to select using mouse.
but now i have done all the possible way to use opengl functions but still not able to select :(
I am using folowing code to pick :
Code:
def pick3d( self, event ):
# 1. initialization
x = event.x()
y = event.y()
pixels = 5
buffer_size = 512
viewport = GL.glGetIntegerv(GL.GL_VIEWPORT)
# 2. selection logic
GL.glSelectBuffer(buffer_size)
GL.glRenderMode(GL.GL_SELECT)
GL.glInitNames()
GL.glPushName(0);
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glPushMatrix()
GL.glLoadIdentity()
#This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is.
GLU.gluPickMatrix(x, (viewport[3]-y), 5, 5, viewport)
#Apply The Perspective Matrix
GLU.gluPerspective(45, (viewport[2]-viewport[0])/(viewport[3]-viewport[1]), 0.1, 100.0);
GL.glMatrixMode(GL.GL_MODELVIEW) #Select The Modelview Matrix
GL.glLoadIdentity() #Reset The Modelview Matrix
GL.glTranslatef(0.0,0.0,-10.0) #Move Into The Screen 20 Units
# previousviewmatrix = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
# GL.glLoadIdentity()
# GLU.gluPickMatrix( x, viewport[3]-y, 5, 5, viewport )
# GL.glMultMatrixd(previousviewmatrix)
# GL.glMatrixMode(GL.GL_MODELVIEW)
self.makeObject(True)
GL.glMatrixMode(GL.GL_PROJECTION) #Select The Projection Matrix
GL.glPopMatrix() # Pop The Projection Matrix
GL.glMatrixMode(GL.GL_MODELVIEW) # Select The Modelview Matrix
self.buffer=GL.glRenderMode(GL.GL_RENDER)
# GL.glFlush()
# GL.glMatrixMode(GL.GL_PROJECTION)
# GL.glLoadMatrixd(previousviewmatrix)
# self.buffer = GL.glRenderMode(GL.GL_RENDER)
#
# # 3. update graphics
# self.updateGL()
# 4. process selction buffer if control is pressed
return self.processBuffer()
def processBuffer(self):
print len(self.buffer)
print "--------- pick3d ----------"
print " - nhits =", len( self.buffer )
if( len(self.buffer) == 0 ): print "hit nothing"
else:
min = self.buffer[0][0]
for record in self.buffer:
minDepth, maxDepth, names = record
# add all hit objects to selectedObjects
for i in range(len(names)):
if(self.selected.count(names[i]) == 1):
print " - unselected: ", names[i]
self.selected.remove(names[i])
else:
self.selected.append(names[i])
print " - selectedObjects: ", self.selected
return self.selected
can any one help me.. please give me any working simple program for selection