How to integrate VTK with OpenGL?
I have a regular VTK pipeline that works OK: I use a vtkPolyData, set it as input to a vtkXXXFilter, use a vtkPolyDataMapper, and render it in a vtkRenderWindow (using a vtkRenderer). All is OK: my scene is rendered over a white background! I do not use any OpenGL-related classes so far (or, say, I’am not sure what is used in back-end to do the rendering).
Now I need to make this VTK pipeline interact with GLFW/OpenGL: I need to retrieve a GLFWwindow consistent with OpenGL.
Replacing vtkRenderWindow with vtkOpenGLRenderWindow doesn’t compile: my understanding is that this class is not meant to be used directly. Question 1: is this correct?
Replacing vtkRenderWindow with vtkGenericOpenGLRenderWindow compiles but crashes:
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff7c1dae9 in vtkOpenGLState::vtkglBlendFuncSeparate (this=0x5555555ac2e0, val1=770, val2=771, val3=1, val4=771)
at /home/fhoussen/Downloads/VTK-9.2.6/Rendering/OpenGL2/vtkOpenGLState.cxx:873
#2 0x00007ffff7be901a in vtkOpenGLRenderWindow::Start (this=0x5555555abad0) at /home/fhoussen/Downloads/VTK-9.2.6/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx:1291
#3 0x00007ffff75ecfa1 in vtkXRenderWindowInteractor::Initialize (this=0x5555555add90) at /home/fhoussen/Downloads/VTK-9.2.6/Rendering/UI/vtkXRenderWindowInteractor.cxx:347
#1 0x00007ffff7c1dae9 in vtkOpenGLState::vtkglBlendFuncSeparate (this=0x5555555ac2e0, val1=770, val2=771, val3=1, val4=771)
at /home/fhoussen/Downloads/VTK-9.2.6/Rendering/OpenGL2/vtkOpenGLState.cxx:873
873 ::glBlendFuncSeparate(val1, val2, val3, val4);
(gdb) l
868 {
869 cs.BlendFunc[0] = val1;
870 cs.BlendFunc[1] = val2;
871 cs.BlendFunc[2] = val3;
872 cs.BlendFunc[3] = val4;
873 ::glBlendFuncSeparate(val1, val2, val3, val4);
874 }
875 vtkCheckOpenGLErrorsWithStack("glBlendFuncSeparate");
876 }
Question 2: how to fix/avoid this? Seems the crash occurs in ::glBlendFuncSeparate
So I tried to replace vtkRenderWindow with vtkXOpenGLRenderWindow (running on unix - I guess vtkWin32OpenGLRenderWindow is meant to be used on windows): the code compiles and run with no crash. Question 3: is there a class vtkXXXRenderWindow that can be used on both unix/windows/macOS? (I hoped this could be vtkGenericOpenGLRenderWindow)
With vtkXOpenGLRenderWindow, the code compiles but I get a black screen with no data rendered. Question 4: what is missing to get the same scene as I had initially but with OpenGL?