コード例 #1
0
    def __init__(self,
                 args,
                 glWidget=QOpenGLWidget,
                 requestedGLVersion=(2, 1)):
        super(_TestApplication, self).__init__(args)

        glType = QOpenGLContext.openGLModuleType()

        format = QSurfaceFormat()
        format.setDepthBufferSize(24)

        if glType == QOpenGLContext.LibGL:
            info("OPENGL MODULE TYPE", "LibGL")
            format.setVersion(requestedGLVersion[0], requestedGLVersion[1])
            format.setProfile(QSurfaceFormat.CompatibilityProfile)
            format.setOption(QSurfaceFormat.DebugContext)
            QSurfaceFormat.setDefaultFormat(format)
        else:
            info(
                "OPENGL MODULE TYPE",
                "Unknown or LibGLES  <--- this is likely to cause problems down the line"
            )

        self.debugMembers = False

        self.mainWin = QWidget()

        if glWidget == QOpenGLWidget:
            # Only hard code size if we're not using a canvas
            self.mainWin.resize(600, 600)

        self.mainWin.setWindowTitle('TestApplication')

        self.mainWidget = glWidget()

        self.layout = QHBoxLayout(self.mainWin)
        self.layout.addWidget(self.mainWidget)

        self.mainWin.show()

        ctx = QOpenGLContext.currentContext()
        info("GL CURRENT CONTEXT", ctx)

        format = ctx.format()

        info("EFFECTIVE GL VERSION", ctx.format().version())

        self.aboutToQuit.connect(self.applicationClosing)