Created
June 21, 2012 17:51
-
-
Save fmorency/2967336 to your computer and use it in GitHub Desktop.
GLXBadDrawable when using multiple QVTKRenderWindow in a QMdiArea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import vtk | |
from vtk.qt4.QVTKRenderWindowInteractor import * | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
if __name__ == '__main__': | |
#Qt boilerplate | |
app = QApplication(sys.argv) | |
main_window = QMainWindow() | |
main_layout = QHBoxLayout() | |
mdi_area = QMdiArea(main_window) | |
#VTK will render on those frames | |
qframe1 = QFrame() | |
qframe2 = QFrame() | |
qhbox1 = QHBoxLayout() | |
qhbox2 = QHBoxLayout() | |
#Our two Qt VTK RenderWindowInteractor | |
vtk_interactor1 = QVTKRenderWindowInteractor(parent=qframe1) | |
vtk_interactor2 = QVTKRenderWindowInteractor(parent=qframe2) | |
#Each subwindow possess its own VTK interactor | |
qhbox1.addWidget(vtk_interactor1) | |
qframe1.setLayout(qhbox1) | |
mdi_area.addSubWindow(qframe1) | |
qhbox2.addWidget(vtk_interactor2) | |
qframe2.setLayout(qhbox2) | |
mdi_area.addSubWindow(qframe2) | |
#Make the MDI area the central widget | |
main_window.setCentralWidget(QWidget()) | |
main_window.centralWidget().setLayout(main_layout) | |
main_layout.addWidget(mdi_area) | |
#Create our VTK renderer | |
ren1 = vtk.vtkRenderer() | |
vtk_interactor1.GetRenderWindow().AddRenderer(ren1) | |
ren2 = vtk.vtkRenderer() | |
vtk_interactor2.GetRenderWindow().AddRenderer(ren2) | |
#A cone source | |
cone = vtk.vtkConeSource() | |
cone.SetResolution(8) | |
coneMapper = vtk.vtkPolyDataMapper() | |
coneMapper.SetInputConnection(cone.GetOutputPort()) | |
coneActor = vtk.vtkActor() | |
coneActor.SetMapper(coneMapper) | |
#Each renderer will display a cone | |
ren1.AddActor(coneActor) | |
ren2.AddActor(coneActor) | |
#Render our cone | |
vtk_interactor1.GetRenderWindow().Render() | |
vtk_interactor2.GetRenderWindow().Render() | |
main_window.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment