For all of you who would like to have an OpenGL widget for Python. Here you have it! It’s very basic. The minimal thing is to overload the paintGL() method. Here is a screenshot:
Good for prototyping or writing small test programs.
A collection of coding snippets, tips, hints and random thoughts.
For all of you who would like to have an OpenGL widget for Python. Here you have it! It’s very basic. The minimal thing is to overload the paintGL() method. Here is a screenshot:
Good for prototyping or writing small test programs.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Muito bom!
This comment has been removed by the author.
Hi Arne! I am trying to use your PyGLWidget code via qtDesigner (placing a qwidget [qgl] in mainwindow & promoting it to PyGLWidget class) I am able to change backgrounds when initialising etc.The only trouble is that I cant see the triangle no more! (when i click a button it should show up)
I call this inside the designermainwindow class.
def paint_something(self):
self.qgl.paintGL()
glColor3f(1,0,0)
glBegin(GL_LINES)
glVertex3f(0,0,0)
glVertex3f(0,1,0)
glEnd()
Any help? Thanks Mate!
Hello Chaitanya!
Hm, I am not sure if you are doing this right. The correct way would be to derive from my class, and overload the paintGL() function, just as I showed in the test.py example program. Your paint_something function might run into the problem that the GL context is not made current or something similar. If you override the paintGL function instead, Qt will make sure that makeCurrent() has been called.
Best regards,
Arne
Thanks Arne!
Hey Arne! So, I wrote a pick function, to your PyGLWidget, to pick objects from the opengl canvas.
glRenderMode(GL_SELECT)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluPickMatrix(self.last_point_2D_.x(),viewport[3]-self.last_point_2D_.y(),10,10,viewport)
glMultMatrixf(projection)
glInitNames()
glPushName(0)
#i scene objects go here
glLoadName(i)
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glFlush()
glPopName()
This works perfect if i do not use gTanslate or glRotated in drawing the object i.e, this code works, when i draw,
glVertex3f(1,1,1)
glVertex3f(2,2,2)
but not when i do,
glTranslate(1,1,1)
glVertex3f(0,0,0)
glVertex3f(1,1,1)
What am i missing? Much Appreciate your help.
Hm, it's too long ago that I did picking in that manner. Nowadays one usually implements color picking — most simple of all is to draw you scene unshaded, and give every object a different color, and then to read the pixel that the mouse clicked on. One would do the rendering in an offscreen FBO or in the backbuffer.
I suggest you head over to something like http://stackoverflow.com/ to get an answer. There is a whole crowd of people being able to help.
A quick google search throws up this tutorial: http://www.lighthouse3d.com/opengl/picking/index.php3?color1