def __init__(self, parent=None): super().__init__(parent) # multisampling fmt = QSurfaceFormat(self.format()) fmt.setSamples(4) fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer) self.setFormat(fmt) self.lists = None self.clearLists = False self.waveform_data = None # if not none, it will be rendered and deleted (to None) self.beatgrid_data = None # if not none, it will be rendered and deleted (to None) self.data_lock = Lock() self.time_offset = 0 self.zoom_seconds = 4 self.pitch = 1 # affects animation speed self.viewport = (50, 40) # viewport +- x, y self.waveform_lines_per_x = 150 self.baseline_height = 0.2 self.position_marker_width = 0.3 self.waveform_zoom_changed_signal.connect(self.setZoom) self.update_interval = 0.04 self.startTimer(self.update_interval*1000)
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 __init__(self): super().__init__() fmt = QSurfaceFormat() fmt.setVersion(2, 0) fmt.setProfile(QSurfaceFormat.CompatibilityProfile) fmt.setStereo(False) fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer) self.setSurfaceType(QWindow.OpenGLSurface) self.context = QOpenGLContext() self.context.setFormat(fmt) if not self.context.create(): raise Exception("Unable to create context") self.create() self.setTitle("OpenGL")
glutPassiveMotionFunc(motion_func) glutKeyboardFunc(keyboard_func) glutMainLoop() elif toolkit == "qt5": from PyQt5.QtCore import Qt, QEvent from PyQt5.QtGui import (QGuiApplication, QWindow, QSurfaceFormat, QOpenGLContext, QOpenGLPaintDevice) app = QGuiApplication(sys.argv) window = QWindow() format = QSurfaceFormat() format.setSwapBehavior(QSurfaceFormat.DoubleBuffer) format.setSamples(16) format.setStencilBufferSize(8) if core: format.setProfile(QSurfaceFormat.CoreProfile) window.setSurfaceType(QWindow.OpenGLSurface) window.setFormat(format) window.setTitle(name) pixel_ratio = window.devicePixelRatio() window.resize(*(u/pixel_ratio for u in window_size)) gl_context = QOpenGLContext(window) gl_context.setFormat(window.requestedFormat()) gl_context.create()
from OpenGL import GL as gl import ctypes import numpy as np import math from .linalg import quaternion as q from .transforms import * from .gloo import * # import threading DEFAULT_FORMAT = QSurfaceFormat() DEFAULT_FORMAT.setVersion(3, 3) DEFAULT_FORMAT.setProfile(QSurfaceFormat.CoreProfile) DEFAULT_FORMAT.setStereo(False) DEFAULT_FORMAT.setSwapBehavior(QSurfaceFormat.DoubleBuffer) DEFAULT_FORMAT.setDepthBufferSize(24) DEFAULT_FORMAT.setSamples(4) 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)