def set_format() -> QSurfaceFormat: surface_format = QSurfaceFormat() surface_format.setVersion(4, 1) surface_format.setProfile(QSurfaceFormat.CoreProfile) surface_format.setSamples(4) QSurfaceFormat.setDefaultFormat(surface_format) return surface_format
def defaultFormat(stereo_capable): fmt = QSurfaceFormat() fmt.setRenderableType(QSurfaceFormat.OpenGL) fmt.setVersion(3, 2) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer) fmt.setRedBufferSize(8) fmt.setGreenBufferSize(8) fmt.setBlueBufferSize(8) fmt.setDepthBufferSize(8) fmt.setAlphaBufferSize(8) fmt.setStencilBufferSize(0) fmt.setStereo(stereo_capable) fmt.setSamples(0) return fmt
def defaultVtkFormat(stereo_capable): """ Po prostu skopiowałem to z https://github.com/Kitware/VTK/blob/master/GUISupport/Qt/QVTKRenderWindowAdapter.cxx i działa poprawnie bufor głębokości """ fmt = QSurfaceFormat() fmt.setRenderableType(QSurfaceFormat.OpenGL) fmt.setVersion(3, 2) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer) fmt.setRedBufferSize(8) fmt.setGreenBufferSize(8) fmt.setBlueBufferSize(8) fmt.setDepthBufferSize(8) fmt.setAlphaBufferSize(8) fmt.setStencilBufferSize(0) fmt.setStereo(stereo_capable) fmt.setSamples(0) return fmt
def defaultSurfaceFormat(stereo_capable): """ Ported from: https://github.com/Kitware/VTK/blob/master/GUISupport/Qt/QVTKRenderWindowAdapter.cxx """ fmt = QSurfaceFormat() fmt.setRenderableType(QSurfaceFormat.OpenGL) fmt.setVersion(3, 2) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer) fmt.setRedBufferSize(8) fmt.setGreenBufferSize(8) fmt.setBlueBufferSize(8) fmt.setDepthBufferSize(8) fmt.setAlphaBufferSize(8) fmt.setStencilBufferSize(0) fmt.setStereo(stereo_capable) fmt.setSamples(0) return fmt
self.imageView.setVisible(1) self.imageView.setPixmap(QPixmap(qimage[0]).scaledToWidth(400)) self.glWidget.updateImage(qimage[0]) def showSaveDialog(self): filename = QFileDialog.getSaveFileName(self, "Save file", "", ".STL") print(filename[0]) self.glWidget.generateSTL(filename[0] + filename[1]) if __name__ == '__main__': app = QApplication(sys.argv) fmt = QSurfaceFormat() if "--multisample" in QCoreApplication.arguments(): fmt.setSamples(4) if "--coreprofile" in QCoreApplication.arguments(): fmt.setVersion(3, 2) fmt.setProfile(QSurfaceFormat.CoreProfile) QSurfaceFormat.setDefaultFormat(fmt) mainWindow = Window() if "--transparent" in QCoreApplication.arguments(): mainWindow.setAttribute(Qt.WA_TranslucentBackground) mainWindow.setAttribute(Qt.WA_NoSystemBackground, False) mainWindow.resize(mainWindow.sizeHint()) mainWindow.show() res = app.exec_() sys.exit(res)
if event.buttons() & Qt.LeftButton: self.setXRotation(self.xRot + 8 * dy) self.setYRotation(self.yRot + 8 * dx) elif event.buttons() & Qt.RightButton: self.setXRotation(self.xRot + 8 * dy) self.setZRotation(self.zRot + 8 * dx) self.lastPos = QPoint(event.pos()) if __name__ == '__main__': app = QApplication(sys.argv) fmt = QSurfaceFormat() fmt.setDepthBufferSize(24) if "--multisample" in QCoreApplication.arguments(): fmt.setSamples(4) if "--coreprofile" in QCoreApplication.arguments(): fmt.setVersion(3, 2) fmt.setProfile(QSurfaceFormat.CoreProfile) QSurfaceFormat.setDefaultFormat(fmt) mainWindow = Window() if "--transparent" in QCoreApplication.arguments(): mainWindow.setAttribute(Qt.WA_TranslucentBackground) mainWindow.setAttribute(Qt.WA_NoSystemBackground, False) mainWindow.resize(mainWindow.sizeHint()) mainWindow.show() res = app.exec_() sys.exit(res)
def keyPressEvent(self, event): key = event.key() if key == Qt.Key_Escape: exit() elif key == Qt.Key_W: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) elif key == Qt.Key_S: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) 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_())
setAllowsAutomaticWindowTabbing = sel_registerName( b'setAllowsAutomaticWindowTabbing:') # class_respondsToSelector does not work (for class methods) if class_getClassMethod(NSWindow, setAllowsAutomaticWindowTabbing): # [NSWindow setAllowsAutomaticWindowTabbing: NO] objc_msgSend( NSWindow, setAllowsAutomaticWindowTabbing, ctypes.c_bool(False), ) fix_macos_nswindow_tabbing() f = QSurfaceFormat() f.setDepthBufferSize(24) f.setSamples(4) QSurfaceFormat.setDefaultFormat(f) class DebugApp(QApplication): def notify(self, x, y): if (x.__class__ == QWindow and y.__class__ == QMouseEvent): x.event(y) return True if (y.__class__ == QMouseEvent): print('App:', x, y) print(y.isAccepted(), int(y.buttons()), int(y.source())) return super().notify(x, y) class MacMouseReleaseFilter(QObject):
import sys from PySide2.QtCore import QCoreApplication, QPoint, QSize, Qt from PySide2.QtGui import QSurfaceFormat from PySide2.QtWidgets import QApplication from window import Window if __name__ == '__main__': fmt = QSurfaceFormat() fmt.setRenderableType(QSurfaceFormat.OpenGL) fmt.setVersion(2, 1) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer) fmt.setSwapInterval(1) fmt.setStereo(False) fmt.setSamples(0) fmt.setRedBufferSize(8) fmt.setGreenBufferSize(8) fmt.setBlueBufferSize(8) fmt.setAlphaBufferSize(8) fmt.setDepthBufferSize(24) fmt.setStencilBufferSize(1) QSurfaceFormat.setDefaultFormat(fmt) app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
#* https://github.com/Kitware/VTK/blob/master/GUISupport/Qt/QVTKOpenGLNativeWidget.cxx fmt = QSurfaceFormat() fmt.setRenderableType(QSurfaceFormat.OpenGL) fmt.setVersion(3, 2) fmt.setProfile(QSurfaceFormat.CoreProfile) fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer) fmt.setRedBufferSize(8) fmt.setGreenBufferSize(8) fmt.setBlueBufferSize(8) fmt.setDepthBufferSize(8) fmt.setAlphaBufferSize(8) fmt.setStencilBufferSize(0) fmt.setStereo(True) fmt.setSamples( 0 ) # we never need multisampling in the context since the FBO can support multisamples independently class SquircleInFboRenderer(QQuickFramebufferObject.Renderer): def __init__(self): super().__init__() self.squircle = SquircleRenderer() self.__fbo = None # self.squircle.initialize() # self.update() def render(self): self.squircle.render() # self.update()