473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Selection, picking with PyOpenGL?

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 :
Expand|Select|Wrap|Line Numbers
  1.     def pick3d( self, event ):
  2.  
  3.         # 1. initialization
  4.  
  5.         x = event.x()
  6.         y = event.y()
  7.         pixels = 5
  8.         buffer_size = 512
  9.         viewport = GL.glGetIntegerv(GL.GL_VIEWPORT)
  10.  
  11.         # 2. selection logic
  12.         GL.glSelectBuffer(buffer_size)
  13.         GL.glRenderMode(GL.GL_SELECT)
  14.         GL.glInitNames()
  15.         GL.glPushName(0);
  16.         GL.glMatrixMode(GL.GL_PROJECTION)
  17.         GL.glPushMatrix()
  18.         GL.glLoadIdentity() 
  19.  
  20.         #This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is.
  21.         GLU.gluPickMatrix(x, (viewport[3]-y), 5, 5, viewport)
  22.         #Apply The Perspective Matrix
  23.         GLU.gluPerspective(45, (viewport[2]-viewport[0])/(viewport[3]-viewport[1]), 0.1, 100.0);
  24.  
  25.         GL.glMatrixMode(GL.GL_MODELVIEW)                                    #Select The Modelview Matrix
  26.         GL.glLoadIdentity()                                           #Reset The Modelview Matrix
  27.         GL.glTranslatef(0.0,0.0,-10.0)                                #Move Into The Screen 20 Units
  28.  
  29. #        previousviewmatrix = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
  30. #        GL.glLoadIdentity()
  31. #        GLU.gluPickMatrix( x, viewport[3]-y, 5, 5, viewport )
  32. #        GL.glMultMatrixd(previousviewmatrix)
  33. #        GL.glMatrixMode(GL.GL_MODELVIEW)
  34.         self.makeObject(True)
  35.  
  36.         GL.glMatrixMode(GL.GL_PROJECTION) #Select The Projection Matrix
  37.         GL.glPopMatrix() # Pop The Projection Matrix
  38.         GL.glMatrixMode(GL.GL_MODELVIEW) # Select The Modelview Matrix
  39.         self.buffer=GL.glRenderMode(GL.GL_RENDER)        
  40.  
  41. #        GL.glFlush()
  42. #        GL.glMatrixMode(GL.GL_PROJECTION)
  43. #        GL.glLoadMatrixd(previousviewmatrix)
  44. #        self.buffer = GL.glRenderMode(GL.GL_RENDER)
  45. #        
  46. #        # 3. update graphics
  47. #        self.updateGL()
  48.  
  49.         # 4. process selction buffer if control is pressed        
  50.         return self.processBuffer()
  51.  
  52.     def processBuffer(self):
  53.         print len(self.buffer)
  54.         print "--------- pick3d ----------"
  55.         print " - nhits =", len( self.buffer )
  56.         if( len(self.buffer) == 0 ): print "hit nothing"
  57.         else:
  58.             min = self.buffer[0][0]
  59.         for record in self.buffer:
  60.            minDepth, maxDepth, names = record
  61.            # add all hit objects to selectedObjects
  62.            for i in range(len(names)):
  63.                if(self.selected.count(names[i]) == 1):
  64.                    print " - unselected: ", names[i]
  65.                    self.selected.remove(names[i])
  66.                else:
  67.                    self.selected.append(names[i])                 
  68.         print " - selectedObjects: ", self.selected
  69.  
  70.         return self.selected




can any one help me.. please give me any working simple program for selection
Oct 8 '09 #1
0 2414

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jimmy Johns | last post by:
Hi, why hasn't there a version of pyOpenGL for python 2.3.x yet? Currently the binary installers for windows only work with python 2.2, and will give an when installing for python 2.3. I can't...
3
by: Steven Gutstein | last post by:
This is probably a fairly newbie type problem, but I'm trying to use PyOpenGL, and don't seem to have installed it correctly. I'm running Python 2.3 on a Windows NT machine. Whenever I go into...
2
by: Erik Max Francis | last post by:
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,...
5
by: Sébastien Ramage | last post by:
Bonjour à tous, Dans la folie j'ai installé le nouveau python, impatient de voir les nouveautés mais je pense que j'ai été un peu rapide car j'ai voulu utiliser pyOpenGL et là problème il...
1
by: joroy | last post by:
Hi all, I think this is ctypes related but how can I call the glShaderSourceARB function? The function have this header: glShaderSourceARB( GLhandleARB(shaderObj), GLsizei(count),...
0
by: sweetmelon | last post by:
(I'm a newbie in Python and pyOpenGL.) Environment: WinXP SP2 Python ver. 2.5 WingIDE easy_install is installed PIL, pyNum is installed Download PyOpenGL-3.0.0a5-py2.5.egg run: easy_install...
0
by: shirish | last post by:
Hi all, Is it possible to have Python+Pygame+PyOpenGL in one compact package so people can play the games released at pyweek.org . I have been having a hard time getting the whole thing on windows...
2
by: seb.haase | last post by:
Hi, I am distributing a package with a precompiled collection of modules and packages useful for Python based medical/biological/astronomical image analysis and algorithm development. (Codename:...
0
by: Colin J. Williams | last post by:
I have just installed PyOpenGL and get a series of warning messages: Best match: PyOpenGL 3.0.0b3 Downloading...
1
by: Clay Hobbs | last post by:
I need a tutorial for PyOpenGL (specifically, to be used with wxPython). I searched with Google and didn't find one. Does anybody know where one is? -- Ratfink
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.