Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. A few basic changes in PyQt6 and PySide6 regarding shader-based OpenGL graphics
Forum Updated to NodeBB v4.3 + New Features

A few basic changes in PyQt6 and PySide6 regarding shader-based OpenGL graphics

Scheduled Pinned Locked Moved Game Development
3 Posts 1 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 25 Jun 2022, 21:44 last edited by 8Observer8
    #1

    These changes also apply to PySide6:

    1. OpenGL classes have been moved to a separate PyQt6.QtOpenGL namespace:

    PyQt5:

    from PyQt5.QtGui import (QOpenGLBuffer, QOpenGLShader, QOpenGLShaderProgram,
                             QOpenGLTexture)
    

    PyQt6:

    from PyQt6.QtOpenGL import (QOpenGLBuffer, QOpenGLShader, QOpenGLShaderProgram,
                                QOpenGLTexture)
    
    1. The QOpenGLWidget class has been moved to the PyQt6.QtOpenGLWidgets namespace:

    PyQt5:

    from PyQt5.QtWidgets import QApplication, QOpenGLWidget
    

    PyQt6:

    from PyQt6.QtOpenGLWidgets import QOpenGLWidget
    
    1. Changed enum for shader types:

    PyQt5:

    self.program.addShaderFromSourceCode(QOpenGLShader.Vertex, vertShaderSrc)
    self.program.addShaderFromSourceCode(QOpenGLShader.Fragment, fragShaderSrc)
    

    PyQt6:

    self.program.addShaderFromSourceCode(QOpenGLShader.ShaderTypeBit.Vertex, vertShaderSrc)
    self.program.addShaderFromSourceCode(QOpenGLShader.ShaderTypeBit.Fragment, fragShaderSrc)
    
    1. Changed enum Target texture:

    PyQt5:

    self.texture = QOpenGLTexture(QOpenGLTexture.Target2D)
    

    PyQt6:

    self.texture = QOpenGLTexture(QOpenGLTexture.Target.Target2D)
    
    1. Changed enum for setting texture filters:

    PyQt5:

    self.texture.setMinMagFilters(QOpenGLTexture.Linear, QOpenGLTexture.Linear)
    

    PyQt6:

    self.texture.setMinMagFilters(QOpenGLTexture.Filter.Linear, QOpenGLTexture.Filter.Linear)
    
    1. Changed enum for WrapMode:

    PyQt5:

    self.texture.setWrapMode(QOpenGLTexture.ClampToEdge)
    

    PyQt6:

    self.texture.setWrapMode(QOpenGLTexture.WrapMode.ClampToEdge)
    
    1. Changed enum to set application attributes:

    PyQt5:

    QApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
    

    PyQt6:

    QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseDesktopOpenGL)
    

    A few basic non-graphical changes:

    1. Changed enum for file open mode:

    PyQt5:

    file = QFile(path)
    if not file.open(QIODevice.ReadOnly):
        print("Failed to open the file: " + path)
    

    PyQt6:

    file = QFile(path)
    if not file.open(QIODevice.OpenModeFlag.ReadOnly):
        print("Failed to open the file: " + path)
    
    1. The QApplication.exec_() method has been renamed to QApplication.exec()

    PyQt5:

    import sys
    from PyQt5.QtWidgets import QApplication
    
    app = QApplication(sys.argv)
    sys.exit(app.exec_())
    

    PyQt6:

    import sys
    from PyQt6.QtWidgets import QApplication
    
    app = QApplication(sys.argv)
    sys.exit(app.exec())
    
    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8Observer8
      wrote on 25 Jun 2022, 22:13 last edited by 8Observer8
      #2

      Some examples on shader OpenGL and PyQt5:

      • Triangle: https://rextester.com/KWYGH93003
      • Texture on a rectangle: https://rextester.com/JNC31813
      • Loading a 3D model from a .dae (Collada) file and physics on the Bullet Physics physics engine: https://github.com/8Observer8/falling-dae-cubes-opengl-pyqt5
      1 Reply Last reply
      0
      • 8 Offline
        8 Offline
        8Observer8
        wrote on 26 Jun 2022, 09:57 last edited by 8Observer8
        #3

        The falling COLLADA (.dae) cube using PySide6, PyQt6, Bullet Physics, and OpenGL 3.3:

        • PySide6: https://github.com/8Observer8/falling-collada-cube-bullet-physics-opengl33-pyside6
        • PyQt6: https://github.com/8Observer8/falling-collada-cube-bullet-physics-opengl33-pyqt6

        You should install these packages:

        • pip install PySide6 (or PyQt6)
        • pip install PyOpenGL
        • pip install numpy
        • pip install Panda3D (for Bullet Physics)

        falling-collada-cube.gif

        1 Reply Last reply
        0

        1/3

        25 Jun 2022, 21:44

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved