[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Programs that need opengl won't run.
From:       Erik Hvatum <ice.rikh () gmail ! com>
Date:       2014-07-23 20:00:49
Message-ID: CAJOi7ytJcaqH1vTsbVKhhNRAf3wvQk=oP5gtik8bhB+rgc7-PA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Firstly, I have had trouble with OpenGL_accelerate from time to time - I
would try uninstalling OpenGL_accelerate while keeping plain pyopengl to
see if that helps anything.

I think QOpenGLFunctions in PyQt is incomplete simply because there are a
heck of a lot of OpenGL functions and many of them want void* blobs that
would take significant wrapping and infrastructure to present in a sensible
way, which PyOpenGL already does tolerably.

That said, it is possible to use the new Qt5 QWindow and QOpenGLContext
stuff together with PyOpenGL in Python on an OpenGL 2.0 context.  Here's a
little example I threw together doing that:

#!/usr/bin/env python3

from OpenGL import GL
from PyQt5 import Qt

class GlQWindow(Qt.QWindow):
    def __init__(self):
        super().__init__()
        format = Qt.QSurfaceFormat()
        format.setVersion(2, 0)
        format.setProfile(Qt.QSurfaceFormat.CompatibilityProfile)
        format.setStereo(False)
        format.setSwapBehavior(Qt.QSurfaceFormat.DoubleBuffer)
        self.setSurfaceType(Qt.QWindow.OpenGLSurface)
        self.context = Qt.QOpenGLContext()
        self.context.setFormat(format)
        if not self.context.create():
            raise Exception('self.context.create() failed')
        self.create()

    def exposeEvent(self, ev):
        ev.accept()
        if self.isExposed() and self.isVisible():
            self.update()

    def makeCurrent(self):
        self.context.makeCurrent(self)

    def swapBuffers(self):
        self.context.swapBuffers(self)

    def update(self):
        self.makeCurrent()
        GL.glClearColor(0,0,0,0)
        GL.glClearDepth(1)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glBegin(GL.GL_TRIANGLES)
        GL.glVertex2f(0.5, 1)
        GL.glVertex2f(1, 0)
        GL.glVertex2f(0, 0)
        GL.glEnd()
        GL.glFlush()
        self.swapBuffers()


app = Qt.QApplication([])
glQWindow = GlQWindow()
glQWindowWidget = Qt.QWidget.createWindowContainer(glQWindow, None,
Qt.Qt.Widget)
glQWindowWidget.show()
app.exec_()

This wasn't exactly the easiest to figure out, but it works quite well, and
it can be extended to support drawing on the OpenGL context from a
different thread by doing
glQWindow.context.moveToThread(a_qthread_instance).
QOpenGLContext.swapBuffers(..) is thread safe, FYI, or is at least safe to
call from the thread owning the context.

Incidentally, if your Qt binaries were compiled with OpenGL ES support
only, you're going to want to rebuild them with *desktop* OpenGL support
enabled.  I mention this only because I went through a period of total
confusion as a result of having ES only binaries.  The official binaries
from qt-project.org are all built with desktop OpenGL support, except for
Android and iOS, of course.

-Erik

On Wed, Jul 23, 2014 at 12:15 PM, Alan Ezust <alan.ezust@gmail.com> wrote:

> I am trying to do openGL on a virtual machine, which only supports OpenGL
> 2.1
> I've checked that my directX version is 11
>
> Most of of the PyQt examples don't work because (I think) our openGL is
> only 2.1 on the virtual machines.
> However, openGLWindow.py works fine, and spits out no errors.
>
> The other examples run but spits out lots of errors, and I can't see
> anything in the windows.
> Here is the output of grabber.py:
>
> C:\Python33\python.exe
> C:/Python33/Lib/site-packages/PyQt5/examples/opengl/grabber.py
> Traceback (most recent call last):
>   File "C:/Python33/Lib/site-packages/PyQt5/examples/opengl/grabber.py",
> line 114, in initializeGL
>     glLightfv(GL_LIGHT0, GL_POSITION, lightPos)
>   File "latebind.pyx", line 32, in
> OpenGL_accelerate.latebind.LateBind.__call__
> (c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\latebind.c:989)
>   File "wrapper.pyx", line 318, in
> OpenGL_accelerate.wrapper.Wrapper.__call__
> (c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\wrapper.c:6561)
>   File "wrapper.pyx", line 311, in
> OpenGL_accelerate.wrapper.Wrapper.__call__
> (c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\wrapper.c:6439)
>   File "C:\Python33\lib\site-packages\OpenGL\platform\baseplatform.py",
> line 402, in __call__
>     return self( *args, **named )
>   File "errorchecker.pyx", line 53, in
> OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError
> (c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\errorchecker.c:1218)
> OpenGL.error.GLError: GLError(
>     err = 1282,
>     description = b'invalid operation',
>     baseOperation = glLightfv,
>     pyArgs = (
>         GL_LIGHT0,
>         GL_POSITION,
>         <OpenGL.raw.GL._types.c_float_Array_4 object at 0x03227800>,
>     ),
>     cArgs = (
>         GL_LIGHT0,
>         GL_POSITION,
>         <OpenGL.raw.GL._types.c_float_Array_4 object at 0x03227800>,
>     ),
>     cArguments = (
>         GL_LIGHT0,
>         GL_POSITION,
>         <OpenGL.raw.GL._types.c_float_Array_4 object at 0x03227800>,
>     )
> )
>
> 2dpainting.py, helloGL.py and overpainting.py do the same thing as
> grabber.py
>
> The main difference with openGLWindow compared to the other examples is
> that it uses Qt's initializeOpenGLFunctions() to get access to openGL API
> of the correct version. This seems to be safer across multiple platforms
> than using OpenGL Apis directly, as the other examples do.
>
>        if needsInitialize:
>             self.m_gl = self.m_context.versionFunctions()
>             self.m_gl.initializeOpenGLFunctions()
>
> Do the other examples even check to see what version of openGL is running?
>
> Is there any reason why QOpenGLFunctions is not available from PyQt?
>
>
>
>
> On Sun, Mar 2, 2014 at 4:41 AM, Matthew Ngaha <chigga101@gmail.com> wrote:
>
>> Hey David. I've updated and re-updated the drivers to no avail. But
>> what really puzzles me is my card is Intel (R) HD graphics. My mum's
>> PC uses an earlier version of the same driver and Qt5 programs run
>> fine. But mine a more recent version doesn't work. I now realise it's
>> not a Qt problem, maybe I can contact Intel's support desk.
>>
>> Thanks for heloing.
>> _______________________________________________
>> PyQt mailing list    PyQt@riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
>
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

[Attachment #5 (text/html)]

<div dir="ltr"><div><div><div><div>Firstly, I have had trouble with OpenGL_accelerate \
 from time to time - I would try uninstalling OpenGL_accelerate while 
keeping plain pyopengl to see if that helps anything.<br><br></div>
I think QOpenGLFunctions in PyQt is incomplete simply because there are a
 heck of a lot of OpenGL functions and many of them want void* blobs 
that would take significant wrapping and infrastructure to present in a 
sensible way, which PyOpenGL already does tolerably.<br>
<br></div>That said, it is possible to use the new Qt5 QWindow and 
QOpenGLContext stuff together with PyOpenGL in Python on an OpenGL 2.0 
context.   Here&#39;s a little example I threw together doing that:<br><br><span \
style="font-family:courier new,monospace">#!/usr/bin/env python3<br> <br>from OpenGL \
import GL<br>from PyQt5 import Qt<br><br>class GlQWindow(Qt.QWindow):<br>       def \
__init__(self):<br>               super().__init__()<br>               format = \
Qt.QSurfaceFormat()<br>               format.setVersion(2, 0)<br>

               format.setProfile(Qt.QSurfaceFormat.CompatibilityProfile)<br>          \
format.setStereo(False)<br>               \
format.setSwapBehavior(Qt.QSurfaceFormat.DoubleBuffer)<br>               \
self.setSurfaceType(Qt.QWindow.OpenGLSurface)<br>

               self.context = Qt.QOpenGLContext()<br>               \
self.context.setFormat(format)<br>               if not self.context.create():<br>    \
raise Exception(&#39;self.context.create() failed&#39;)<br>               \
self.create()<br>

<br>       def exposeEvent(self, ev):<br>               ev.accept()<br>               \
if self.isExposed() and self.isVisible():<br>                       \
self.update()<br><br>       def makeCurrent(self):<br>               \
self.context.makeCurrent(self)<br><br>

       def swapBuffers(self):<br>               \
self.context.swapBuffers(self)<br><br>       def update(self):<br>               \
self.makeCurrent()<br>               GL.glClearColor(0,0,0,0)<br>               \
GL.glClearDepth(1)<br>               GL.glClear(GL.GL_COLOR_BUFFER_BIT | \
GL.GL_DEPTH_BUFFER_BIT)<br>

               GL.glBegin(GL.GL_TRIANGLES)<br>               GL.glVertex2f(0.5, \
1)<br>               GL.glVertex2f(1, 0)<br>               GL.glVertex2f(0, 0)<br>    \
GL.glEnd()<br>               GL.glFlush()<br>               \
self.swapBuffers()<br><br><br>app = Qt.QApplication([])<br>

glQWindow = GlQWindow()<br>glQWindowWidget = \
Qt.QWidget.createWindowContainer(glQWindow, None, \
Qt.Qt.Widget)<br>glQWindowWidget.show()<br>app.exec_()</span><br><br></div>This  \
wasn&#39;t exactly the easiest to figure out, but it works quite well, and  it can be \
extended to support drawing on the OpenGL context from a  different thread by doing \
glQWindow.context.moveToThread(a_qthread_instance).   QOpenGLContext.swapBuffers(..) \
is thread safe, FYI, or is at least safe to call from the thread owning the \
context.<br> <br></div>Incidentally, if your Qt binaries were compiled with OpenGL ES
 support only, you&#39;re going to want to rebuild them with *desktop* 
OpenGL support enabled.   I mention this only because I went through a 
period of total confusion as a result of having ES only binaries.   The 
official binaries from <a href="http://qt-project.org" \
target="_blank">qt-project.org</a> are all built with desktop OpenGL support, except \
for Android and iOS, of course.<div class="gmail_extra"><br></div><div \
                class="gmail_extra">
-Erik<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 23, \
2014 at 12:15 PM, Alan Ezust <span dir="ltr">&lt;<a \
href="mailto:alan.ezust@gmail.com" \
target="_blank">alan.ezust@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div>I am trying to do openGL on a virtual \
machine, which only supports OpenGL 2.1<br>I&#39;ve checked that my directX version \
is 11<br> <br>Most of of the PyQt examples don't work because (I think) our openGL is \
only 2.1 on the virtual machines. <br> However, openGLWindow.py works fine, and spits \
out no errors.<br><br>The other examples run but spits out lots of errors, and I \
can't see anything in the windows. <br></div>Here is the output of \
grabber.py:<br><div><br>C:\Python33\python.exe \
C:/Python33/Lib/site-packages/PyQt5/examples/opengl/grabber.py<br>

Traceback (most recent call last):<br>   File \
&quot;C:/Python33/Lib/site-packages/PyQt5/examples/opengl/grabber.py&quot;, line 114, \
in initializeGL<br>       glLightfv(GL_LIGHT0, GL_POSITION, lightPos)<br>   File \
&quot;latebind.pyx&quot;, line 32, in OpenGL_accelerate.latebind.LateBind.__call__ \
(c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\latebind.c:989)<br>

   File &quot;wrapper.pyx&quot;, line 318, in \
OpenGL_accelerate.wrapper.Wrapper.__call__ \
(c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\wrapper.c:6561)<br> \
File &quot;wrapper.pyx&quot;, line 311, in OpenGL_accelerate.wrapper.Wrapper.__call__ \
(c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\wrapper.c:6439)<br>

   File &quot;C:\Python33\lib\site-packages\OpenGL\platform\baseplatform.py&quot;, \
line 402, in __call__<br>       return self( *args, **named )<br>   File \
&quot;errorchecker.pyx&quot;, line 53, in \
OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError \
(c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\errorchecker.c:1218)<br>


OpenGL.error.GLError: GLError(<br>       err = 1282,<br>       description = \
b&#39;invalid operation&#39;,<br>       baseOperation = glLightfv,<br>       pyArgs = \
(<br>              GL_LIGHT0,<br>              GL_POSITION,<br>              \
&lt;OpenGL.raw.GL._types.c_float_Array_4 object at 0x03227800&gt;,<br>

       ),<br>       cArgs = (<br>              GL_LIGHT0,<br>              \
GL_POSITION,<br>              &lt;OpenGL.raw.GL._types.c_float_Array_4 object at \
0x03227800&gt;,<br>       ),<br>       cArguments = (<br>              GL_LIGHT0,<br> \
GL_POSITION,<br>

              &lt;OpenGL.raw.GL._types.c_float_Array_4 object at 0x03227800&gt;,<br>  \
)<br>)<br><br>2dpainting.py, helloGL.py and overpainting.py do the same thing as \
grabber.py<br><br>The main difference with openGLWindow compared to the other \
examples is that it uses Qt's initializeOpenGLFunctions() to get access to openGL API \
of the correct version. This seems to be safer across multiple platforms than using \
OpenGL Apis directly, as the other examples do.<br>

<br>             if needsInitialize:<br>                       self.m_gl = \
self.m_context.versionFunctions()<br>                       \
self.m_gl.initializeOpenGLFunctions()<br><br></div><div>Do the other examples even \
check to see what version of openGL is running? <br>

</div><div><br>Is there any reason why QOpenGLFunctions is not available from PyQt? \
<br><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On \
Sun, Mar 2, 2014 at 4:41 AM, Matthew Ngaha <span dir="ltr">&lt;<a \
href="mailto:chigga101@gmail.com" target="_blank">chigga101@gmail.com</a>&gt;</span> \
wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Hey David. I&#39;ve updated and re-updated the drivers to no \
avail. But<br> what really puzzles me is my card is Intel (R) HD graphics. My \
mum&#39;s<br> PC uses an earlier version of the same driver and Qt5 programs run<br>
fine. But mine a more recent version doesn&#39;t work. I now realise it&#39;s<br>
not a Qt problem, maybe I can contact Intel&#39;s support desk.<br>
<br>
Thanks for heloing.<br>
<div><div>_______________________________________________<br>
PyQt mailing list      <a href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a><br> <a \
href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br> \
</div></div></blockquote></div><br></div> \
<br>_______________________________________________<br> PyQt mailing list      <a \
href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br> <a \
href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br></div></div>



[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic