def initializeGL(self): f = QSurfaceFormat() #f.setVersion(2, 2) f.setDepthBufferSize(32) p = QOpenGLVersionProfile(f) self.gl = self.context().versionFunctions(p) self.gl.initializeOpenGLFunctions() self.setClearColor(self._bgColor) self.loadObject() if not BATCH_MODE: self.loadTargetImageMeta( self.systemModel.asteroid.sample_image_meta_file) self.gl.glEnable(self.gl.GL_CULL_FACE) # for transparent asteroid image on top of model self.gl.glBlendFunc(self.gl.GL_SRC_ALPHA, self.gl.GL_ONE_MINUS_SRC_ALPHA) if self._render: self._rendOpts() else: self._projOpts() if not BATCH_MODE: self.loadTargetImage(self.systemModel.asteroid.sample_image_file)
def __init__(self, ddsFile, debugContext=False, parent=None, f=Qt.WindowFlags()): super(DDSWidget, self).__init__(parent, f) self.ddsFile = ddsFile self.clean = True self.logger = None self.program = None self.transparecyProgram = None self.texture = None self.vbo = None self.vao = None self.backgroundColour = None if debugContext: format = QSurfaceFormat() format.setOption(QSurfaceFormat.DebugContext) self.setFormat(format) self.logger = QOpenGLDebugLogger(self)
def __init__(self): QQuickView.__init__(self) surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.setColor(QColor(0, 0, 0, 0)) self.setFlags( Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.X11BypassWindowManagerHint ) self.setResizeMode(QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.set_all_contexts() self.setSource(QUrl.fromLocalFile(os.path.join( ROOT_LOCATION, 'frame', 'views', 'Main.qml'))) self.connect_all_object_function() self.engine_obj = self.engine() connect_to_primary_changed(self.display_primary_changed) self._dbus_adptor = DssDbusAdptor(self) qApp.focusWindowChanged.connect(self.onFocusWindowChanged)
def __init__(self, parent=None): super().__init__(parent) if USE_OPENGL and not isRemoteSession(): fmt = QSurfaceFormat() fmt.setSamples(4) self.setViewport(QOpenGLWidget()) self.viewport().setFormat(fmt) self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) else: self.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate) layout = QFormLayout(self) layout.setContentsMargins(0, 0, 6, 0) layout.setFormAlignment(Qt.AlignRight | Qt.AlignBottom) self.minimap = MiniMapGraphicsView(self) layout.addWidget(self.minimap) self.setLayout(layout) self.setCacheMode(QGraphicsView.CacheBackground) self.setRenderHint(QPainter.Antialiasing) self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.setResizeAnchor(QGraphicsView.AnchorViewCenter) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setOptimizationFlags(QGraphicsView.DontSavePainterState | QGraphicsView.DontAdjustForAntialiasing) self.setStyleSheet( """NetworkView:focus { border: 3px solid palette(highlight); }""")
def __init__(self, *args): super().__init__(*args) self.setMinimumSize(300, 300) fmt = QSurfaceFormat() fmt.setSamples(4) self.setFormat(fmt)
def qt_qml_opengl(multi_windows_script='', qml_dirs=[], img_providers=[]): # Create the application instance. # app = QGuiApplication(sys.argv) --> CRASH app = QApplication(sys.argv) #https://machinekoder.com/how-to-not-shoot-yourself-in-the-foot-using-python-qt/ timer = QTimer() timer.timeout.connect(lambda: None) timer.start(100) # app = QApplication(sys.argv) QSurfaceFormat.setDefaultFormat(create_format()) if multi_windows_script: engine = create_multi_windows( try_to_complete_path(multi_windows_script, qml_dirs), qml_dirs, img_providers, app) view = engine.rootObjects()[0] else: view = create_qquick_view(os.path.join(QMLDIR, "root.qml"), qml_dirs, img_providers) view.show() exit(app.exec_())
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()
def __init__(self, context): QQuickView.__init__(self) self.context = context self.settings = context.settings surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.set_cursor_shape("shape_start_cursor") self.setColor(QColor(0, 0, 0, 0)) self.setFlags(Qt.X11BypassWindowManagerHint | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setResizeMode(QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.setTitle(_("Deepin Screenshot")) self.qimage = QImage(self.settings.tmpImageFile) self.qpixmap = QPixmap() self.qpixmap.convertFromImage(self.qimage) self.window_info = context.windowInfo self._grabPointerStatus = False self._grabKeyboardStatus = False self._grabFocusTimer = self._getGrabFocusTimer()
def __init__(self, settings, windowInfo): QQuickView.__init__(self) self._settings = settings surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.set_cursor_shape("shape_start_cursor") self.setColor(QColor(0, 0, 0, 0)) self.setFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setResizeMode(QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.setTitle(_("Deepin screenshot")) self.qimage = QImage(self._settings.tmpImageFile) self.qpixmap = QPixmap() self.qpixmap.convertFromImage(self.qimage) self.window_info = windowInfo self._grabPointerStatus = False self._grabKeyboardStatus = False self._grabFocusTimer = self._getGrabFocusTimer() self._osdShowed = False self._osdShowing = False self._quitOnOsdTimeout = False
def setDefaultFormat(cls, major_version: int, minor_version: int, core=False, profile=None) -> None: """Set the default format for each new OpenGL context :param major_version: :param minor_version: :param core: (optional) True for QSurfaceFormat.CoreProfile, False for CompatibilityProfile :param profile: (optional) QSurfaceFormat.CoreProfile, CompatibilityProfile or NoProfile, overrules option core """ 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_) QSurfaceFormat.setDefaultFormat(new_format) cls.major_version = major_version cls.minor_version = minor_version cls.profile = profile_
def __init__(self, *args, samples=4, **kwargs): super().__init__(*args, **kwargs) self.is_dragging = False self.mouse_location = None self.renderer = None self.camera = PerspectiveCamera() format_ = QSurfaceFormat() format_.setSamples(samples) self.setFormat(format_)
def toggleOpenGL(self): vp = QWidget() if self.openGlButton.isChecked(): fmt = QSurfaceFormat() fmt.setSamples(8) vp = QOpenGLWidget() vp.setFormat(fmt) self.graphicsView.setViewport(vp)
def __init__(self): QQuickView.__init__(self) surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.setColor(QColor(0, 0, 0, 0)) self.setFlags(QtCore.Qt.FramelessWindowHint) self.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.qml_context = self.rootContext()
def __init__(self, obj_path, parent=None): super().__init__(parent) surface_format = QSurfaceFormat() surface_format.setSamples(16) QOpenGLWidget.setFormat(self, surface_format) self.projection = QMatrix4x4() self.vertex_buf_offsets = [3, 3, 2] #position, normal, tex_coord self.vertex_buf_stride = sum(self.vertex_buf_offsets) self.obj_path = obj_path self.initialized = False
def setContext(cls, major_version: int, minor_version: int, 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
def setContext(cls, major_version: int, minor_version: int, core=False, profile=None): """Set OpenGL context, given major, minor version + core using QOpenGLContext Unfortunately, what you get back does not have to be the requested version. """ 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
def __init__(self, scene, projection=None, navigation=None, parent=None): # super init super().__init__(parent) fmt = QSurfaceFormat() fmt.setVersion(*opengl_version) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setSamples(4) self.setFormat(fmt) self.setFocusPolicy(Qt.StrongFocus) self.setAttribute(Qt.WA_AcceptTouchEvents, True) # interaction methods self.projection = projection or globals()[settings.scene['projection']]() self.navigation = navigation or globals()[settings.controls['navigation']]() self.tool = [Tool(self.navigation.tool, self)] # tool stack, the last tool is used for input events, until it is removed # render parameters self.scene = scene if isinstance(scene, Scene) else Scene(scene) self.uniforms = {'proj':fmat4(1), 'view':fmat4(1), 'projview':fmat4(1)} # last frame rendering constants self.targets = [] self.steps = [] self.step = 0 self.stepi = 0 # dump targets self.map_depth = None self.map_idents = None self.fresh = set() # set of refreshed internal variables since the last render
def __init__(self, scene, camera, light): super().__init__() fmt = QSurfaceFormat() fmt.setVersion(3, 3) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setStencilBufferSize(8) self.setFormat(fmt) self.scene, self.camera, self.light = scene, camera, light
def setDefaultFormat(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_) QSurfaceFormat.setDefaultFormat(new_format) cls.major_version = major_version cls.minor_version = minor_version cls.profile = profile_
def __init__(self, parent=None, title="A Marc Paint Widget", view_bounds=(0, 1, 0, 1), window_size=(500, 500), bg_color=(0.0, 0.0, 0.0, 1.0), textures=None): super().__init__(parent) this_format = QSurfaceFormat() this_format.setSamples(16) self.setFormat(this_format) # note: textures takes the form {name: path to image} if textures is None: textures = {} self.textures = {} self.textures_to_load = textures self.setWindowTitle(title) self.view_bounds = view_bounds self.setGeometry((get_screen_width() - window_size[0])/2, (get_screen_height() - window_size[1])/2, window_size[0], window_size[1]) self.bg_color = bg_color self.setAutoFillBackground(False) self.last_resize = None self.resize_mode = ResizeModes.ANCHOR_MIDDLE self.squash_factor = float(self.get_view_width()) * self.height() / self.width() / self.get_view_height() # track mouse movements self.setMouseTracking(True) # this stores the current mouse view location self._mouse_view_location = (0, 0) self.click_started = False self.click_buttons = None self.click_count = 1 self.last_click = -1 # be sensitive to the pinch gesture self.grabGesture(4) # key event stuff self._keys_down = [] self.use_shift_sensitive_key_codes = False # animation timer self.timer = QTimer(self) self.timer.timeout.connect(self._do_animate_frame) QTimer().singleShot(0, self.on_load) self.last_animate = None self.animation_layers = [] # shapes to be drawn self._shapes = []
def __init__(self, obj_path, parent=None): super().__init__(parent) surface_format = QSurfaceFormat() surface_format.setSamples(16) QOpenGLWidget.setFormat(self, surface_format) self.projection = QMatrix4x4() self.vertex_buf_offsets = [3, 3, 2] # position, normal, tex_coord self.vertex_buf_stride = sum(self.vertex_buf_offsets) self.obj_path = obj_path self.initialized = False if not has_libGL: get_main_window().show_status( 'OpenGL library not found. Disabling 3D view.')
def __init__(self, center=False): QQuickView.__init__(self) self._center_request_count = 1 if center else 0 surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.setColor(QColor(0, 0, 0, 0)) self.setMinimumSize(QSize(MINIMIZE_WIDTH, MINIMIZE_HEIGHT)) self.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.staysOnTop = False self.qml_context = self.rootContext() self.setTitle(_("Deepin Movie")) self.setIcon(icon_from_theme("Deepin", "deepin-movie")) self.setDeepinWindowShadowHint(self.windowGlowRadius)
def __init__(self, emacs_xid, init_width, init_height): QQuickView.__init__(self) surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.setColor(QColor(0, 0, 0, 0)) self.setFlags(QtCore.Qt.FramelessWindowHint) self.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.qml_context = self.rootContext() self.emacs_xid = int(emacs_xid) self.emacs_width = int(init_width) self.emacs_height = int(init_height) self.show()
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")
def __init__(self, center=False): QQuickView.__init__(self) self._center_request_count = 1 if center else 0 surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.setColor(QColor(0, 0, 0, 0)) self.setMinimumSize(QSize(MINIMIZE_WIDTH, MINIMIZE_HEIGHT)) self.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.setFlags(QtCore.Qt.FramelessWindowHint) self.staysOnTop = False self.qml_context = self.rootContext() self.setTitle(_("Deepin Movie")) self.setIcon(icon_from_theme("Deepin", "deepin-movie")) self.setDeepinWindowShadowHint(self.windowGlowRadius)
def show_menu(view, injection): qml_context = view.rootContext() # qml_context.setContextProperty("_menu_items", ) qml_context.setContextProperty("_menu_view", view) qml_context.setContextProperty("_application", qApp) qml_context.setContextProperty("_injection", injection) view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView) view.setMinimumSize(QSize(70, 50)) surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) view.setFormat(surface_format) view.setColor(QColor(0, 0, 0, 0)) view.setFlags(QtCore.Qt.Popup) view.setSource(QtCore.QUrl.fromLocalFile(os.path.join(os.path.dirname(__file__), 'FullScreenMenu.qml'))) view.show()
def __init__(self, script, qml_dirs = [], img_providers = []): ''' script is assumed to contain a 'key' property which is updated on Keys.onPressed events. script's API is assumed to be its root level properties ''' self.app = QApplication(sys.argv) ## This remove the following warning at the started of the viewer : QML Settings: The following application identifiers have not been set: QVector("organizationName", "organizationDomain") self.app.setOrganizationName("Leddartech") self.app.setOrganizationDomain("Advanced_Engineering") # https://machinekoder.com/how-to-not-shoot-yourself-in-the-foot-using-python-qt/ self.timer = QTimer() self.timer.timeout.connect(lambda: None) self.timer.start(100) QSurfaceFormat.setDefaultFormat(utils.create_format()) self.engine = None self.root = None self.view = None if script: self.create_view(script, qml_dirs, img_providers)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.is_dragging = False self.mouse_location = None self.renderer = None self.camera = PerspectiveCamera() format_ = QSurfaceFormat() format_.setSamples(4) self.setFormat(format_) self.setAcceptDrops(True) # cursor_file_name = pkg_resources.resource_filename( 'wiggle.images', 'cross-hair.png') cursor_pixmap = QPixmap(cursor_file_name) cross_hair_cursor = QCursor(cursor_pixmap, 15, 15) self.setCursor(cross_hair_cursor) self.setMouseTracking(True) # Hover event self.main_window = None self.hover_actor = None self.has_hover_effect = False
def __init__(self, parent): QOpenGLWidget.__init__(self, parent=parent) # Adding samples format = QSurfaceFormat() format.setSamples(8) self.setFormat(format) self.programLocations: Dict[str, GLuint] self.view: View = View() self.functionModel = FunctionModel(2) self.axesModel = AxisModel() self.evalPointsModel = EvalPointsModel() self.evalLinesModel = EvalLinesModel() self.userModels = [] self.locations = {} self.screenView = None self.mouse: List[int] = None self.setMouseTracking(True)
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): super(ViewerWidget, self).__init__(parent) self.main_window = parent # Add antialiasing format = QSurfaceFormat() format.setSamples(8) self.setFormat(format) # Global viewer attributes self.camera = Camera(self.size()) self.global_uniforms = {} self.global_uniforms["lightDirection"] = np.array([0.0, 0.0, 1.0]) self.global_uniforms["lightDirection"] /= np.linalg.norm( self.global_uniforms["lightDirection"] ) self.global_uniforms["lightIntensity"] = np.array([0.95, 0.95, 0.95]) self.global_uniforms["ambientLighting"] = np.array([0.05, 0.05, 0.05]) self.global_uniforms["cameraPosition"] = self.camera.get_position() self.global_uniforms["linkLight"] = False self.line_width = 1 self.point_size = 3 # Available shaders self.shaders = {} # Mesh attributes self.mesh_groups = {} self.draw_wireframe = True # Mouse input handling self.mouse_handler = MouseHandler() self.setMouseTracking(True) # Event queues self.mesh_events = Queue() self.post_draw_events = Queue()
def main(): queue = Queue(maxsize=1000) world = World(queue, DEFAULT_UNIV_X, DEFAULT_UNIV_Y, BOTS_AT_BEGINNING, MINERALS_AT_BEGINNING) world.start() # app = QApplication(sys.argv) # widget = Qwidget(queue, DEFAULT_UNIV_X, DEFAULT_UNIV_Y, SCALE) # app.exec_() # # print(queue.qsize()) app = QApplication(sys.argv) fmt = QSurfaceFormat() fmt.setSamples(4) QSurfaceFormat.setDefaultFormat(fmt) window = WorldWindow(queue, DEFAULT_UNIV_X, DEFAULT_UNIV_Y, SCALE) window.show() app.exec_() world.finish_him() world.join()
def __init__(self, qml_file): QQuickView.__init__(self) surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) self.setColor(QColor(0, 0, 0, 0)) self.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView) self.setFormat(surface_format) self.setFlags(QtCore.Qt.Popup) self.qml_context = self.rootContext() self.init_translate_info() self.qml_context.setContextProperty("translateInfo", self.translate_info) self.qml_context.setContextProperty("windowView", self) self.qml_context.setContextProperty("settingConfig", setting_config) self.qml_context.setContextProperty("qApp", qApp) self.setSource(QtCore.QUrl.fromLocalFile(os.path.join(get_parent_dir(__file__), qml_file)))
def __init__(self, scene, projection=None, navigation=None, parent=None): # super init super(QOpenGLWidget, self).__init__(parent) fmt = QSurfaceFormat() fmt.setVersion(*opengl_version) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setSamples(4) self.setFormat(fmt) # ugly trick to receive interaction events in a different function than QOpenGLWidget.event (that one is locking the GIL during the whole rendering, killing any possibility of having a computing thread aside) # that event reception should be in the current widget ... self.handler = GhostWidget(self) self.handler.setFocusPolicy(Qt.StrongFocus) self.handler.setAttribute(Qt.WA_AcceptTouchEvents, True) ViewCommon.__init__(self, scene, projection=None, navigation=None) self.tool = [ Tool(self.navigation.tool, self) ] # tool stack, the last tool is used for input events, until it is removed
def __init__(self, engine=None, parent=None): super(DQuickView, self).__init__(engine, parent) self.setResizeMode(QtQuick.QQuickView.SizeViewToRootObject) self.engine().addImportPath(os.sep.join([get_parent_dir(__file__, 2), 'qml'])) if isWebengineUsed: # self.initWebengine() pass format = QSurfaceFormat() format.setAlphaBufferSize(8) format.setRenderableType(QSurfaceFormat.OpenGL) self.setFormat(format) self.setColor(QColor(Qt.transparent)) self.setClearBeforeRendering(True)
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
__author__ = 'akirayu101' from PyQt5.QtGui import (QGuiApplication, QSurfaceFormat) from akira_shader import AkiraRenderWindow if __name__ == '__main__': import sys app = QGuiApplication(sys.argv) surface_format = QSurfaceFormat() surface_format.setSamples(4) window = AkiraRenderWindow() window.setFormat(surface_format) window.resize(800, 600) window.show() window.setAnimating(True) sys.exit(app.exec_())
self.setLayout(mainLayout) self.currentGlWidget = self.glWidgets[0][0] timer = QTimer(self) timer.timeout.connect(self.rotateOneStep) timer.start(20) self.setWindowTitle("Textures") def setCurrentGlWidget(self): self.currentGlWidget = self.sender() def rotateOneStep(self): if self.currentGlWidget: self.currentGlWidget.rotateBy(+2 * 16, +2 * 16, -1 * 16) if __name__ == '__main__': app = QApplication(sys.argv) format = QSurfaceFormat() format.setDepthBufferSize(24) QSurfaceFormat.setDefaultFormat(format) window = Window() window.show() sys.exit(app.exec_())
rect = metrics.boundingRect(0, 0, self.width() - 2*border, int(self.height()*0.125), Qt.AlignCenter | Qt.TextWordWrap, text) painter.setRenderHint(QPainter.TextAntialiasing) painter.fillRect(QRect(0, 0, self.width(), rect.height() + 2*border), QColor(0, 0, 0, 127)) painter.setPen(Qt.white) painter.fillRect(QRect(0, 0, self.width(), rect.height() + 2*border), QColor(0, 0, 0, 127)) painter.drawText((self.width() - rect.width())/2, border, rect.width(), rect.height(), Qt.AlignCenter | Qt.TextWordWrap, text) def setClearColor(self, c): self.gl.glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()) def setColor(self, c): self.gl.glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF()) if __name__ == '__main__': app = QApplication(sys.argv) fmt = QSurfaceFormat() fmt.setSamples(4) QSurfaceFormat.setDefaultFormat(fmt) window = GLWidget() window.show() sys.exit(app.exec_())
self.translate = False def wheelEvent(self,event) : numPixels = event.pixelDelta(); if numPixels.x() > 0 : self.modelPos.m_z += self.ZOOM elif numPixels.x() < 0 : self.modelPos.m_z -= self.ZOOM self.update(); if __name__ == '__main__': app = QApplication(sys.argv) format=QSurfaceFormat() format.setSamples(4); format.setMajorVersion(4); format.setMinorVersion(1); format.setProfile(QSurfaceFormat.CoreProfile); # now set the depth buffer to 24 bits format.setDepthBufferSize(24); # set that as the default format for all windows QSurfaceFormat.setDefaultFormat(format); window = MainWindow() window.setFormat(format) window.resize(1024,720) window.show() sys.exit(app.exec_())
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))
#! /usr/bin/env python3.6 from __future__ import print_function, division, absolute_import import posix,posixpath,sys, re if sys.version_info.major > 2: basestring = str from PyQt5.QtCore import QCoreApplication, Qt from PyQt5.QtGui import QSurfaceFormat fmt = QSurfaceFormat.defaultFormat() fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setRedBufferSize(8); fmt.setGreenBufferSize(8); fmt.setBlueBufferSize(8); fmt.setAlphaBufferSize(8); fmt.setDepthBufferSize(24); fmt.setStencilBufferSize(8); version_str = posix.environ.get(b'AV_PLAYER_OGL_VERSION',None) version = None if version_str: try: match = version_re.match(version_str) if match: version = (int(match.group(1)),int(match.group(2))) except: pass if version is None:
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.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.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() 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()
from PyQt5.QtGui import QSurfaceFormat, QColor from read_conf import confList, create_qml from PyQt5 import Qt from tray_icon import TrayIcon from settingWindow import SettingWindow import subprocess if __name__=="__main__": app = QApplication(sys.argv) signal.signal(signal.SIGINT, signal.SIG_DFL) view = QQuickView() view.setFlags(Qt.Qt.FramelessWindowHint) surface_format = QSurfaceFormat() surface_format.setAlphaBufferSize(8) view.setFormat(surface_format) view.setColor(QColor(0, 0, 0, 0)) view.setResizeMode(QQuickView.SizeRootObjectToView) create_qml() t_icon=TrayIcon() sw=SettingWindow() def show_window(): path='screen.qml' view.engine().quit.connect(app.quit) view.setSource(QUrl(path)) desktop=QApplication.desktop() x=(desktop.width()-1000)/2
int(self.height()*0.125), Qt.AlignCenter, text) painter.setRenderHint(QPainter.TextAntialiasing) painter.fillRect(QRect(0, 0, self.width(), rect.height() + 2*border), QColor(0, 0, 0, 127)) painter.setPen(Qt.white) painter.fillRect(QRect(0, 0, self.width(), rect.height() + 2*border), QColor(0, 0, 0, 127)) painter.drawText((self.width() - rect.width())/2, border, rect.width(), rect.height(), Qt.AlignCenter | Qt.TextWordWrap, text) if __name__ == '__main__': import sys app = QApplication(sys.argv) format = QSurfaceFormat() format.setSamples(4) format.setDepthBufferSize(24) format.setOption(QSurfaceFormat.DebugContext) window = WaterWindow() window.setFormat(format) window.resize(640, 480) window.showMaximized() window.setAnimating(True) sys.exit(app.exec_())
0.0, 0.0, 1.0]) gl.glVertexAttribPointer(self.m_colAttr, 3, gl.GL_FLOAT, False, 0, colors) gl.glEnableVertexAttribArray(self.m_colAttr) gl.glDrawArrays(gl.GL_TRIANGLES, 0, 3) self.m_program.release() self.m_frame += 1 if __name__ == '__main__': import sys app = QGuiApplication(sys.argv) format = QSurfaceFormat() format.setSamples(4) window = TriangleWindow() window.setFormat(format) window.resize(640, 480) window.show() window.setAnimating(True) sys.exit(app.exec_())