当前位置: 首页>>代码示例>>Python>>正文


Python QtGui.QOpenGLContext类代码示例

本文整理汇总了Python中PyQt5.QtGui.QOpenGLContext的典型用法代码示例。如果您正苦于以下问题:Python QOpenGLContext类的具体用法?Python QOpenGLContext怎么用?Python QOpenGLContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QOpenGLContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self) -> None:
        if OpenGL.__instance is not None:
            raise RuntimeError("Try to create singleton '%s' more than once" % self.__class__.__name__)
        OpenGL.__instance = self

        super().__init__()

        profile = QOpenGLVersionProfile()
        profile.setVersion(OpenGLContext.major_version, OpenGLContext.minor_version)
        profile.setProfile(OpenGLContext.profile)

        self._gl = QOpenGLContext.currentContext().versionFunctions(profile) # type: Any #It's actually a protected class in PyQt that depends on the implementation of your graphics card.
        if not self._gl:
            Logger.log("e", "Startup failed due to OpenGL initialization failing")
            QMessageBox.critical(None, i18n_catalog.i18nc("@message", "Failed to Initialize OpenGL", "Could not initialize OpenGL. This program requires OpenGL 2.0 or higher. Please check your video card drivers."))
            sys.exit(1)

        # It would be nice to be able to not necessarily need OpenGL FrameBuffer Object support, but
        # due to a limitation in PyQt, currently glReadPixels or similar methods are not available.
        # This means we can only get frame buffer contents through methods that indirectly call
        # those methods, in this case primarily QOpenGLFrameBufferObject::toImage(), making us
        # hard-depend on FrameBuffer Objects.
        if not self.hasFrameBufferObjects():
            Logger.log("e", "Startup failed, OpenGL does not support Frame Buffer Objects")
            QMessageBox.critical(None, i18n_catalog.i18nc("Critical OpenGL Extensions Missing", "Critical OpenGL extensions are missing. This program requires support for Framebuffer Objects. Please check your video card drivers."))
            sys.exit(1)

        self._gl.initializeOpenGLFunctions()

        self._gpu_vendor = OpenGL.Vendor.Other #type: int
        vendor_string = self._gl.glGetString(self._gl.GL_VENDOR)
        if vendor_string is None:
            vendor_string = "Unknown"
        vendor_string = vendor_string.lower()

        if "nvidia" in vendor_string:
            self._gpu_vendor = OpenGL.Vendor.NVidia
        elif "amd" in vendor_string or "ati" in vendor_string:
            self._gpu_vendor = OpenGL.Vendor.AMD
        elif "intel" in vendor_string:
            self._gpu_vendor = OpenGL.Vendor.Intel

        # WORKAROUND: Cura/#1117 Cura-packaging/12
        # Some Intel GPU chipsets return a string, which is not undecodable via PyQt5.
        # This workaround makes the code fall back to a "Unknown" renderer in these cases.
        try:
            self._gpu_type = self._gl.glGetString(self._gl.GL_RENDERER) #type: str
        except UnicodeDecodeError:
            Logger.log("e", "DecodeError while getting GL_RENDERER via glGetString!")
            self._gpu_type = "Unknown" #type: str

        self._opengl_version = self._gl.glGetString(self._gl.GL_VERSION) #type: str

        if not self.hasFrameBufferObjects():
            Logger.log("w", "No frame buffer support, falling back to texture copies.")

        Logger.log("d", "Initialized OpenGL subsystems.")
        Logger.log("d", "OpenGL Version:  %s", self._opengl_version)
        Logger.log("d", "OpenGL Vendor:   %s", self._gl.glGetString(self._gl.GL_VENDOR))
        Logger.log("d", "OpenGL Renderer: %s", self._gpu_type)
开发者ID:Ultimaker,项目名称:Uranium,代码行数:60,代码来源:OpenGL.py

示例2: _initialize

    def _initialize(self):
        profile = QOpenGLVersionProfile()
        profile.setVersion(2, 0)
        self._gl = QOpenGLContext.currentContext().versionFunctions(profile)
        self._gl.initializeOpenGLFunctions()

        self._default_material = self.createMaterial(
                                     Resources.getPath(Resources.Shaders, "default.vert"),
                                     Resources.getPath(Resources.Shaders, "default.frag")
                                )

        self._default_material.setUniformValue("u_ambientColor", Color(0.3, 0.3, 0.3, 1.0))
        self._default_material.setUniformValue("u_diffuseColor", Color(0.5, 0.5, 0.5, 1.0))
        self._default_material.setUniformValue("u_specularColor", Color(0.7, 0.7, 0.7, 1.0))
        self._default_material.setUniformValue("u_shininess", 20.)

        self._selection_buffer = self.createFrameBuffer(128, 128)
        self._selection_material = self.createMaterial(
                                        Resources.getPath(Resources.Shaders, "basic.vert"),
                                        Resources.getPath(Resources.Shaders, "color.frag")
                                   )

        self._handle_material = self.createMaterial(
                                     Resources.getPath(Resources.Shaders, "basic.vert"),
                                     Resources.getPath(Resources.Shaders, "vertexcolor.frag")
                                )

        self._outline_material = self.createMaterial(
                                      Resources.getPath(Resources.Shaders, "outline.vert"),
                                       Resources.getPath(Resources.Shaders, "outline.frag")
                                 )

        self._initialized = True
开发者ID:mesut-pehlivan,项目名称:Uranium,代码行数:33,代码来源:QtGL2Renderer.py

示例3: create

 def create(self):
     from PyQt5.QtGui import QOpenGLContext
     self._id = gl.glGenTextures(1)
     context = QOpenGLContext.currentContext()
     self._opengl_context = context
     from seamless import add_opengl_destructor
     add_opengl_destructor(context, self.destroy)
开发者ID:agoose77,项目名称:seamless,代码行数:7,代码来源:GLStore.py

示例4: renderNow

    def renderNow(self):
        if not self.isExposed():
            return

        self.m_update_pending = False

        needsInitialize = False

        if self.m_context is None:
            self.m_context = QOpenGLContext(self)
            self.m_context.setFormat(self.requestedFormat())
            self.m_context.create()

            needsInitialize = True

        self.m_context.makeCurrent(self)

        if needsInitialize:
            self.m_gl = self.m_context.versionFunctions()
            self.m_gl.initializeOpenGLFunctions()

            self.initialize()

        self.render(self.m_gl)

        self.m_context.swapBuffers(self)

        if self.m_animating:
            self.renderLater()
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:29,代码来源:openglwindow.py

示例5: initializeGL

 def initializeGL(self):
     import seamless
     from PyQt5.QtGui import QOpenGLContext
     if self._destroyed:
         return
     try:
         old_running_qt = seamless._running_qt
         seamless._running_qt = True
         activate_opengl()
         ctx = self.context()
         assert ctx is QOpenGLContext.currentContext()
         #print("start initializeGL")
         if not self._initialized:
             add_opengl_context(ctx)
             self._initialized = True
         self.camera.width = self.width()
         self.camera.height = self.height()
         self.camera._write()
         #print("INIT")
         PINS.init.set()
         #print("end initializeGL")
     finally:
         seamless._running_qt = old_running_qt
         deactivate_opengl()
     super().initializeGL()
     seamless.run_work()
开发者ID:sjdv1982,项目名称:seamless,代码行数:26,代码来源:cell-glwindow.py

示例6: renderNow

    def renderNow(self):
        if not self.isExposed():
            return

        self.m_update_pending = False

        needsInitialize = False

        if self.m_context is None:
            self.m_context = QOpenGLContext(self)
            self.surface_format = QSurfaceFormat()
            self.surface_format.setVersion(4, 1)
            self.surface_format.setProfile(QSurfaceFormat.CoreProfile)
            self.m_context.setFormat(self.surface_format)
            self.m_context.create()
            needsInitialize = True

        self.m_context.makeCurrent(self)

        if needsInitialize:
            self.initialize()

        self.render()

        self.m_context.swapBuffers(self)

        if self.m_animating:
            self.renderLater()
开发者ID:akirayu101,项目名称:ShaderLearning,代码行数:28,代码来源:openglwindow.py

示例7: setupUI

 def setupUI(self):  
   self.setSurfaceType(QWindow.OpenGLSurface)
   self.renderctxt = QOpenGLContext(self)
   self.renderctxt.setFormat(self.requestedFormat())
   self.renderctxt.create()
   self.renderctxt.makeCurrent(self)
   self.glfunc = self.renderctxt.versionFunctions()
   self.glfunc.initializeOpenGLFunctions()
开发者ID:mikakev1,项目名称:freetime,代码行数:8,代码来源:__main__.py

示例8: opengl_vendor

def opengl_vendor():  # pragma: no cover
    """Get the OpenGL vendor used.

    This returns a string such as 'nouveau' or
    'Intel Open Source Technology Center'; or None if the vendor can't be
    determined.
    """
    assert QApplication.instance()

    override = os.environ.get('QUTE_FAKE_OPENGL_VENDOR')
    if override is not None:
        log.init.debug("Using override {}".format(override))
        return override

    old_context = QOpenGLContext.currentContext()
    old_surface = None if old_context is None else old_context.surface()

    surface = QOffscreenSurface()
    surface.create()

    ctx = QOpenGLContext()
    ok = ctx.create()
    if not ok:
        log.init.debug("Creating context failed!")
        return None

    ok = ctx.makeCurrent(surface)
    if not ok:
        log.init.debug("Making context current failed!")
        return None

    try:
        if ctx.isOpenGLES():
            # Can't use versionFunctions there
            return None

        vp = QOpenGLVersionProfile()
        vp.setVersion(2, 0)

        try:
            vf = ctx.versionFunctions(vp)
        except ImportError as e:
            log.init.debug("Importing version functions failed: {}".format(e))
            return None

        if vf is None:
            log.init.debug("Getting version functions failed!")
            return None

        return vf.glGetString(vf.GL_VENDOR)
    finally:
        ctx.doneCurrent()
        if old_context and old_surface:
            old_context.makeCurrent(old_surface)
开发者ID:mehak,项目名称:qutebrowser,代码行数:54,代码来源:version.py

示例9: __init__

    def __init__(self, parent=None, **kwargs):
        super(ViewerWindow, self).__init__(parent)
        self.setSurfaceType(QWindow.OpenGLSurface)

        format = QSurfaceFormat()
        format.setVersion(3, 3)
        format.setProfile(QSurfaceFormat.CoreProfile)
        format.setStereo(False)
        format.setSwapBehavior(QSurfaceFormat.DoubleBuffer)
        format.setDepthBufferSize(24)
        format.setSamples(16)
        
        self.context = QOpenGLContext(self)
        self.context.setFormat(format)
        if not self.context.create():
            raise Exception('self.context.create() failed')
        self.create()

        size = 720, 720
        self.resize(*size)

        self.context.makeCurrent(self)
        self.hud_program = CrossHairProgram()

        self.default_view = np.eye(4, dtype=np.float32)
        self.view = self.default_view
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.layer_manager = LayerManager()

        self.visibility_toggle_listeners = []
        self.multiview = True

        self.rotation = q.quaternion()
        self.scale = 0.6
        self.translation = np.zeros(3)

        self.radius = 0.5 * min(*size)
        self.fov = 5.
        self.camera_position = -12.
        self.near_clip = .1
        if 'near_clip' in kwargs:
            self.near_clip = kwargs['near_clip']
        self.far_clip = 100.
        if 'far_clip' in kwargs:
            self.far_clip = kwargs['far_clip']
        

        self.projection_mode = 'perspective' # 'orthographic'

        self.size = size
        self.bg_white = False
        self.viewpoint_dict = {}

        print((self.instructions))
开发者ID:Ylannl,项目名称:povipy,代码行数:56,代码来源:app.py

示例10: sanity_check

 def sanity_check(self):
     from PyQt5.QtGui import QOpenGLContext
     context = QOpenGLContext.currentContext()
     assert context
     assert threading.current_thread() is threading.main_thread()
     if self._opengl_context is not None:
         #assert context is self._opengl_context
         if context is not self._opengl_context:
             self.destroy()
             self.create()
开发者ID:agoose77,项目名称:seamless,代码行数:10,代码来源:GLStore.py

示例11: setContext

    def setContext(cls, major_version, minor_version, core = False, profile = None):
        new_format = QSurfaceFormat()
        new_format.setMajorVersion(major_version)
        new_format.setMinorVersion(minor_version)
        if core:
            profile_ = QSurfaceFormat.CoreProfile
        else:
            profile_ = QSurfaceFormat.CompatibilityProfile
        if profile is not None:
            profile_ = profile
        new_format.setProfile(profile_)

        new_context = QOpenGLContext()
        new_context.setFormat(new_format)
        success = new_context.create()
        if success:
            return new_context
        else:
            Logger.log("e", "Failed creating OpenGL context (%d, %d, core=%s)" % (major_version, minor_version, core))
            return None
开发者ID:senttech,项目名称:Uranium,代码行数:20,代码来源:OpenGLContext.py

示例12: supportsVertexArrayObjects

 def supportsVertexArrayObjects(cls, ctx = None):
     if ctx is None:
         ctx = QOpenGLContext.currentContext()
     result = False
     if cls.major_version == 4 and cls.minor_version >= 1:
         result = True
     if not result and cls.major_version > 4:
         result = True
     if not result and cls.hasExtension("GL_ARB_vertex_array_object", ctx = ctx):
         result = True
     cls.properties["supportsVertexArrayObjects"] = result
     return result
开发者ID:senttech,项目名称:Uranium,代码行数:12,代码来源:OpenGLContext.py

示例13: opengl_vendor

def opengl_vendor():  # pragma: no cover
    """Get the OpenGL vendor used.

    This returns a string such as 'nouveau' or
    'Intel Open Source Technology Center'; or None if the vendor can't be
    determined.
    """
    # We're doing those imports here because this is only available with Qt 5.4
    # or newer.
    from PyQt5.QtGui import (QOpenGLContext, QOpenGLVersionProfile,
                             QOffscreenSurface)
    assert QApplication.instance()

    old_context = QOpenGLContext.currentContext()
    old_surface = None if old_context is None else old_context.surface()

    surface = QOffscreenSurface()
    surface.create()

    ctx = QOpenGLContext()
    ok = ctx.create()
    if not ok:
        log.init.debug("opengl_vendor: Creating context failed!")
        return None

    ok = ctx.makeCurrent(surface)
    if not ok:
        log.init.debug("opengl_vendor: Making context current failed!")
        return None

    try:
        if ctx.isOpenGLES():
            # Can't use versionFunctions there
            return None

        vp = QOpenGLVersionProfile()
        vp.setVersion(2, 0)

        vf = ctx.versionFunctions(vp)
        if vf is None:
            log.init.debug("opengl_vendor: Getting version functions failed!")
            return None

        return vf.glGetString(vf.GL_VENDOR)
    finally:
        ctx.doneCurrent()
        if old_context and old_surface:
            old_context.makeCurrent(old_surface)
开发者ID:swalladge,项目名称:qutebrowser,代码行数:48,代码来源:version.py

示例14: beginRendering

    def beginRendering(self):
        if not self._initialized:
            self._initialize()

        self._gl.glViewport(0, 0, self._viewport_width, self._viewport_height)
        self._gl.glClearColor(self._background_color.redF(), self._background_color.greenF(), self._background_color.blueF(), self._background_color.alphaF())
        self._gl.glClear(self._gl.GL_COLOR_BUFFER_BIT | self._gl.GL_DEPTH_BUFFER_BIT)

        if not QOpenGLContext.currentContext().format().renderableType() == QSurfaceFormat.OpenGLES:
            self._gl.glPointSize(2)

        self._solids_queue.clear()
        self._transparent_queue.clear()
        self._overlay_queue.clear()

        self._render_selection = True
开发者ID:mesut-pehlivan,项目名称:Uranium,代码行数:16,代码来源:QtGL2Renderer.py

示例15: GLWindow

class GLWindow(QWindow):
    def __init__(self):
      super(GLWindow, self).__init__()
      self.title= "GLWindow"
      self.setGeometry(0, 0, 640, 480)
      self.setupUI()
      
    def setupUI(self):  
      self.setSurfaceType(QWindow.OpenGLSurface)
      self.renderctxt = QOpenGLContext(self)
      self.renderctxt.setFormat(self.requestedFormat())
      self.renderctxt.create()
      self.renderctxt.makeCurrent(self)
      self.glfunc = self.renderctxt.versionFunctions()
      self.glfunc.initializeOpenGLFunctions()
开发者ID:mikakev1,项目名称:freetime,代码行数:15,代码来源:__main__.py


注:本文中的PyQt5.QtGui.QOpenGLContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。