PyOpenGL cannot compile shader

I am using Python3, Qt4 and PyOpenGL to test Debian with python3-pyside packages. This is a minified code example:

#!/bin/env python3

from OpenGL.GL import shaders, GL_VERTEX_SHADER
from PySide import QtGui
from PySide.QtOpenGL import QGLWidget

class MyGLWidget(QGLWidget):
    def initializeGL(self):
        self.vertex_shader = shaders.compileShader("""
        #version 330
        layout(location = 0) in vec4 position;
        void main()
        {
            gl_Position = position;
        }
        """, GL_VERTEX_SHADER)

if __name__ == '__main__':
    app = QtGui.QApplication(["shader fail"])
    widget = MyGLWidget()
    widget.show()
    app.exec_()

      

This is mistake:

$ python3 fail.py 
Traceback (most recent call last):
  File "fail.py", line 16, in initializeGL
    """, GL_VERTEX_SHADER)
  File "/usr/lib/python3/dist-packages/OpenGL/GL/shaders.py", line 231, in compileShader
    shaderType,
RuntimeError: ("Shader compile failure (0): b'0:1(13): preprocessor error: syntax error, unexpected HASH_TOKEN\\n'", [b'\n        #version 330\n        layout(location = 0) in vec4 position;\n        void main()\n        {\n            gl_Position = position;\n        }\n        '], GL_VERTEX_SHADER)

      

This is the simplest shader I can think of and the error is not very descriptive. Can you help me?

EDIT: If in initializeGL

I do first print(self.context().format())

, the output is

<PySide.QtOpenGL.QGLFormat(options QFlags(0x1|0x2|0x4|0x8|0x20|0x80|0x400) , plane  0 , depthBufferSize  24 , accumBufferSize  -1 , stencilBufferSize  8 , redBufferSize  8 , greenBufferSize  8 , blueBufferSize  8 , alphaBufferSize  8 , samples  -1 , swapInterval  0 , majorVersion  1 , minorVersion  0 , profile  0 )   at 0x7f66bc804508>

      

This means I am getting the OpenGL 1.0 context. So my guess is that I need to query the higher version context somehow.

As for my graphics hardware: I am using integrated graphics in my Intel i7-4710MQ with the Debian default driver. It identifies lspci as

00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)

      

More interesting:

$ glxinfo | grep -i version
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.4.2
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 10.4.2
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 10.4.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.0

      

So the hardware + driver should be able to do the trick.

Update:

print(int(QGLFormat.openGLVersionFlags()))

      

gives 4223

which includes versions up to 3.0 but not 3.1 or higher, which is strange since up to 3.3 should be available.

If I try to refer to a higher version context like:

fmt = QGLFormat(QGLFormat.OpenGL_Version_3_3 | QGLFormat.CompatibilityProfile)
widget = MyGLWidget(fmt)

      

or try it with Version_3_0

or Version_2_0

with help QGLFormat.NoProfile

, i still get 1.0 version context

+3


source to share





All Articles