本文整理汇总了Python中PyQt5.QtGui.QOpenGLContext.create方法的典型用法代码示例。如果您正苦于以下问题:Python QOpenGLContext.create方法的具体用法?Python QOpenGLContext.create怎么用?Python QOpenGLContext.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QOpenGLContext
的用法示例。
在下文中一共展示了QOpenGLContext.create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GLWindow
# 需要导入模块: from PyQt5.QtGui import QOpenGLContext [as 别名]
# 或者: from PyQt5.QtGui.QOpenGLContext import create [as 别名]
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()
示例2: opengl_vendor
# 需要导入模块: from PyQt5.QtGui import QOpenGLContext [as 别名]
# 或者: from PyQt5.QtGui.QOpenGLContext import create [as 别名]
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)
示例3: opengl_vendor
# 需要导入模块: from PyQt5.QtGui import QOpenGLContext [as 别名]
# 或者: from PyQt5.QtGui.QOpenGLContext import create [as 别名]
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)
示例4: setContext
# 需要导入模块: from PyQt5.QtGui import QOpenGLContext [as 别名]
# 或者: from PyQt5.QtGui.QOpenGLContext import create [as 别名]
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
示例5: OpenGLWindow
# 需要导入模块: from PyQt5.QtGui import QOpenGLContext [as 别名]
# 或者: from PyQt5.QtGui.QOpenGLContext import create [as 别名]
class OpenGLWindow(QWindow):
def __init__(self, parent=None):
super(OpenGLWindow, self).__init__(parent)
self.m_update_pending = False
self.m_animating = False
self.m_context = None
self.m_gl = None
self.setSurfaceType(QWindow.OpenGLSurface)
def initialize(self):
pass
def setAnimating(self, animating):
self.m_animating = animating
if animating:
self.renderLater()
def renderLater(self):
if not self.m_update_pending:
self.m_update_pending = True
QGuiApplication.postEvent(self, QEvent(QEvent.UpdateRequest))
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()
def event(self, event):
if event.type() == QEvent.UpdateRequest:
self.renderNow()
return True
return super(OpenGLWindow, self).event(event)
def exposeEvent(self, event):
self.renderNow()
def resizeEvent(self, event):
self.renderNow()
示例6: OpenGLWindow
# 需要导入模块: from PyQt5.QtGui import QOpenGLContext [as 别名]
# 或者: from PyQt5.QtGui.QOpenGLContext import create [as 别名]
class OpenGLWindow(QWindow):
def __init__(self, parent=None):
super(OpenGLWindow, self).__init__(parent)
self.m_update_pending = False
self.m_animating = False
self.m_context = None
self.m_device = None
self.m_gl = None
self.logger = None
self.setSurfaceType(QWindow.OpenGLSurface)
def initialize(self, gl):
pass
def setAnimating(self, animating):
self.m_animating = animating
if animating:
self.renderLater()
def renderLater(self):
if not self.m_update_pending:
self.m_update_pending = True
QGuiApplication.postEvent(self, QEvent(QEvent.UpdateRequest))
def paint(self, painter):
pass
def render(self, gl):
pass
def addGlFunctuins(self, GL, functions):
for function, arguments in functions.items():
GL[function].restype = None
GL[function].argtypes = arguments
setattr(self.m_gl, function, GL[function])
@exitOnKeyboardInterrupt
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:
# Sorry, no support for higher versions for now.
profile = QOpenGLVersionProfile()
profile.setVersion(2, 0)
self.m_gl = self.m_context.versionFunctions(profile)
self.m_gl.initializeOpenGLFunctions()
#print(self.m_context.hasExtension('GL_EXT_framebuffer_object'))
#print(self.m_context.hasExtension('GL_ARB_texture_float'))
#print(*sorted(self.m_context.extensions()), sep='\n')
# Small hack. Guess noone mind?
import ctypes
import ctypes.util
GL = ctypes.CDLL(ctypes.util.find_library('GL'))
self.addGlFunctuins(GL, {
'glFramebufferTexture2D': (ctypes.c_uint, ctypes.c_uint, ctypes.c_uint, ctypes.c_uint, ctypes.c_int)
})
self.logger = QOpenGLDebugLogger()
self.logger.initialize()
self.logger.loggedMessages()
self.logger.messageLogged.connect(self.handleLoggedMassage)
self.logger.startLogging()
self.initialize(self.m_gl)
if not self.m_device:
self.m_device = QOpenGLPaintDevice()
self.m_gl.glClear(self.m_gl.GL_COLOR_BUFFER_BIT | self.m_gl.GL_DEPTH_BUFFER_BIT);
self.m_device.setSize(self.size())
painter = QPainter(self.m_device)
painter.beginNativePainting()
self.render(self.m_gl)
painter.endNativePainting()
#.........这里部分代码省略.........
示例7: ViewerWindow
# 需要导入模块: from PyQt5.QtGui import QOpenGLContext [as 别名]
# 或者: from PyQt5.QtGui.QOpenGLContext import create [as 别名]
class ViewerWindow(QWindow):
instructions = """
--Key controls
0-9 - toggle data layers
r - reset view parameters
c - clip view
t - view from top
l - light/dark background
= - increase point size
- - decrease point size
--Mouse controls
drag
shift + move - translate dataset
scroll - scale dataset
shift + scroll - change field of view
ctrl + scroll - move far clipping plane
alt + scroll - move near clipping plane
ctrl + alt + scroll - move far and near clipping plane simultaniously
"""
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))
def add_layer(self, layer):
self.layer_manager.add_layer(layer)
return layer
# keeping this compatibility with older scripts
def add_data_source(self, name, opts, points, normals=None, radii=None, intensity=None, category=None, zrange=None, **kwargs):
if len(self.layer_manager.layers) == 0:
self.layer_manager.add_layer(Layer(name='Default'))
self.layer_manager.layers['Default'].add_data_source(name, opts, points, normals=normals, radii=radii, intensity=intensity, category=category, zrange=zrange, **kwargs)
def add_data_source_line(self, name, coords_start, coords_end, **args):
if len(self.layer_manager.layers) == 0:
self.layer_manager.add_layer(Layer(name='Default'))
self.layer_manager.layers['Default'].add_data_source_line(name, coords_start, coords_end, **args)
def add_data_source_triangle(self, name, coords, normals, **args):
if len(self.layer_manager.layers) == 0:
self.layer_manager.add_layer(Layer(name='Default'))
self.layer_manager.layers['Default'].add_data_source_triangle(name, coords, normals, **args)
def run(self):
#.........这里部分代码省略.........