Hi,
I am using Qt6.5.3 with VTK 9.3.1 in Visual Studio. I have 2 QVTKOpenGLNativeWidget both work fine and able to display 3D and 2D, but whenever I change the interactor of the render window, there will be error every time the mouse is moving in the widget.
Error:
Generic Warning: In vtkOpenGLState.cxx, line 1749
Error glBlitFramebuffer1 OpenGL errors detected
0 : (1286) Invalid framebuffer operation
I tried setting the QSurfaceFormat, it doesn’t help.
My minimum goal is to let the 2D renderer to have vtkInteractorStyleImage instead of 3D interaction.
Code:
.h includes
#pragma once
#include <QtWidgets/QMainWindow>
#include <QGridLayout>
#include <QPushButton>
#include <QFileDialog>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageData.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkVolume.h>
#include <vtkVolumeMapper.h>
#include <vtkFixedPointVolumeRayCastMapper.h>
#include <vtkVolumeProperty.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkDICOMImageReader.h>
#include <vtkImageViewer2.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkImageReader2Factory.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderWindowInteractor.h>
#include <QVTKOpenGLNativeWidget.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2); // For OpenGL rendering
VTK_MODULE_INIT(vtkInteractionStyle); // For interaction styles
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2); // For volume rendering with OpenGL
.cpp
#include "MyVTK.h"
MyVTK::MyVTK(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setVersion(3, 3); // Use the appropriate OpenGL version
format.setProfile(QSurfaceFormat::CompatibilityProfile); // Core profile may be required
QSurfaceFormat::setDefaultFormat(format);
QWidget* centralWidget = new QWidget(this);
QGridLayout* layout = new QGridLayout(centralWidget);
// Create VTK widget for 3D display
vtkWidget3D = new QVTKOpenGLNativeWidget(this);
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow3D = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
// Set up 3D interactor style
vtkSmartPointer<vtkRenderWindowInteractor> interactor3D = vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style3D = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
interactor3D->SetInteractorStyle(style3D);
**// SETTING THE INTERACTOR WILL CAUSE THE ERROR**
interactor3D->SetRenderWindow(renderWindow3D);
// Create VTK widget for 2D image display
vtkWidget2D = new QVTKOpenGLNativeWidget(this);
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow2D = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
vtkWidget2D->setRenderWindow(renderWindow2D);
// Set up 2D interactor style
vtkSmartPointer<vtkRenderWindowInteractor> interactor2D = vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleImage> style2D = vtkSmartPointer<vtkInteractorStyleImage>::New();
interactor2D->SetInteractorStyle(style2D);
**// SETTING THE INTERACTOR WILL CAUSE THE ERROR**
interactor2D->SetRenderWindow(renderWindow2D);
// Add widgets and buttons to layout
layout->addWidget(vtkWidget3D, 0, 0);
layout->addWidget(vtkWidget2D, 0, 1);
setCentralWidget(centralWidget);
}
Full Error list:
Generic Warning: In vtkOpenGLState.cxx, line 1749
Error glBlitFramebuffer1 OpenGL errors detected
0 : (1286) Invalid framebuffer operation
with stack trace of
at vtksys::SystemInformationImplementation::GetProgramStack in D:\source\VTK-9.3.1\Utilities\KWSys\vtksys\SystemInformation.cxx line 3987
at vtksys::SystemInformation::GetProgramStack in D:\source\VTK-9.3.1\Utilities\KWSys\vtksys\SystemInformation.cxx line 829
at `anonymous namespace'::reportOpenGLErrors in D:\source\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLState.cxx line 283
at vtkOpenGLState::vtkglBlitFramebuffer in D:\source\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLState.cxx line 1749
at vtkOpenGLRenderWindow::BlitDisplayFramebuffer in D:\source\VTK-9.3.1\Rendering\OpenGL2\vtkOpenGLRenderWindow.cxx line 1568
at QVTKRenderWindowAdapter::QVTKInternals::blit in D:\source\VTK-9.3.1\GUISupport\Qt\QVTKRenderWindowAdapter.cxx line 329
at QVTKRenderWindowAdapter::blit in D:\source\VTK-9.3.1\GUISupport\Qt\QVTKRenderWindowAdapter.cxx line 554
at QVTKOpenGLNativeWidget::paintGL in D:\source\VTK-9.3.1\GUISupport\Qt\QVTKOpenGLNativeWidget.cxx line 265
at QOpenGLWidget::makeCurrent
at QOpenGLWidget::makeCurrent
at QLineEdit::`default constructor closure'
at QOpenGLWidget::makeCurrent
at QVTKOpenGLNativeWidget::event in D:\source\VTK-9.3.1\GUISupport\Qt\QVTKOpenGLNativeWidget.cxx line 290
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QFileInfo::filePath
at QFileInfo::filePath
at QLineEdit::`default constructor closure'
at QOpenGLWidget::makeCurrent
at QLineEdit::`default constructor closure'
at QOpenGLWidget::makeCurrent
at QVTKOpenGLNativeWidget::event in D:\source\VTK-9.3.1\GUISupport\Qt\QVTKOpenGLNativeWidget.cxx line 290
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QFileInfo::filePath
at QFileInfo::filePath
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at QLineEdit::`default constructor closure'
at main in D:\source\GitHub\MyScanCT test\MyScanCT\main.cpp line 9
at qtEntryPoint in C:\Users\qt\work\qt\qtbase\src\entrypoint\qtentrypoint_win.cpp line 50
at WinMain in C:\Users\qt\work\qt\qtbase\src\entrypoint\qtentrypoint_win.cpp line 60
at invoke_main in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl line 107
at __scrt_common_main_seh in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl line 288
at __scrt_common_main in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl line 331
at WinMainCRTStartup in D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_winmain.cpp line 17
at BaseThreadInitThunk
at RtlUserThreadStart
Best regard