getting Error: GLEW could not be initialized: Missing GL version

I tried to update this QML-VTK project from Dao Duc Tung to the current vtk 9.3.0 & PySide6 versions fork.
I run the script on two machines (NVIDIA GTX 4060Ti & NVIDIA RTX A500) on both the situation is the same:
On Linux the project is works (content is rendered).
On Windows the render window does not show the content.
On both OS’s i get the error: vtkExternalOpenGLRenderWindow (0000029E8FD3F070): GLEW could not be initialized: Missing GL version
I read through a lots of posts but didnt find a solution.
Any help will be welcome!

The error probably means that, somewhere in the code, vtkExternalOpenGLRenderWindow is rendered before Qt has created an OpenGL context. Do you know where in the Python code the GLEW error is triggered?

I’m not sure if vtkExternalOpenGLRenderWindow is regularly maintained, so it might be best to try to get this working with vtkGenericOpenGLRenderWindow first. Or, at least make sure that vtkExternalOpenGLRenderWindow is working properly on all your platforms by running the test in C++.

Tank you for the reply.
I tried it with the vtkExternalOpenGLRenderWindow first, but then, also under linux, nothing is rendered (same Error: vtkExternalOpenGLRenderWindow (0x2fa2ee0): GLEW could not be initialized: Missing GL version)

I tried the linked Test on Debian.
I got first the error when running cmake:
CMake Error at /usr/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find GLUT (missing: GLUT_glut_LIBRARY GLUT_INCLUDE_DIR) Call Stack (most recent call first): /usr/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.27/Modules/FindGLUT.cmake:178 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:5 (find_package)

Then i did a apt install libglut-dev and the error was gone.

But now i get the error:
CMake Error at CMakeLists.txt:7 (vtk_add_test_cxx): Unknown CMake command "vtk_add_test_cxx".

So it seemed that this with the lib was the problem? There is also the OPENGL_glu_LIBRARY flag when building vtk where in my case stood OPENGL_glu_LIBRARY-NOTFOUND and now the path is found: /usr/lib/x86_64-linux-gnu/libGLU.so.

I am using python via pip and so I am not familiar with building my own python wheel. Are there any good tutorials how to do that with my own Cpp VTK build version? I guess this could solve the issue?

Thank you so far!

To build the GLUT test, you need to create a new CMakeLists.txt for it (see the VTK C++ examples). The CMakeLists that you used (the one External/Testing/Cxx) can’t be used for building the test as a stand-alone example.

I don’t think that building your own wheel will fix the issue with QML-VTK. Most likely, something has changed between Qt5 and Qt6 in the way that it sets up the OpenGL context.

As I said in my previous message, the best place to start is to find out where in the Python code the GLEW error is being triggered.

I also did debugging the python code and its in the fboRenderer.py line 33: self.rw.OpenGLInitContext(). So when the vtkGeneric/ExternalOpenGLRenderWindow calls the OpenGLInitContext. But that does not brings me any further, or do have a suggestion here?
I tried to write a CmakeLists.txt for that Test, but my skills do not seemed to be enough to get that running. I always get an error in fatal error: vtk_glew.h: No such file or directory 12 | #include <vtk_glew.h>

Nevertheless many thanks again

This is exactly the right starting point. The error tells you that, at this point in the code, there is no OpenGL context. So either the OpenGLInitContext() needs to be done later (after the context exists), or the context has to be created before this point. What happens if you simply comment out line 33?

When i comment out the line I get the error:
warning: queue 0x2ecddd0 destroyed while proxies still attached: wl_registry@36 still attached Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

I tried to call the OpenGLInitContext() later by creating the fboRenderer later in the def setup() of the MainCtrl because i guess that is the point where it has to be made because this is executed when the mainView (qml-file) is active?
But also the same error as when initializing it before.
How can i check if the context is created or better what is the context here? Sorry for the stupid questions.

I have also to say, that in the fboRenderer.render() i commented out the resetOpenGLState() which on Qt6 is replaced by beginExternalCommands() and endExternalCommands(). But also no luck when comment that out or replacing here.

Thank you really much so far and have a nice evening.

There might be some useful information in the source code for QtQuickVTKRenderWindow in VTK. I notice that it has some code that is specifically for Qt 6.

Thank you. I will have take a deeper look at that when i have time later.
But this RenderWindow class is not available/wrapped in the vtk package from pip? Or am I getting here something wrong?
Best regards!

Which RenderWindow are you referring to? The QtQuickVTKRenderWindow? It can only be used from C++, which is why it isn’t in the pip package.

The only Qt/VTK code in the pip package is vtkmodules.qt.QVTKRenderWindowInteractor. And building a new pip package won’t add anything else.

OK I see. Yes I meant the QtQuickVTKRenderWIndow. I thought all Cpp classes are automatically wrapped to python classes and are then published to use them with pip.
I also have seen vtkmodules.qt.QVTKRenderWindowInteractor. But it was the same GLEW could not be initialized: Missing GL version error here. I was not even able to show the cylinder, but that is another thing.

VTK’s Qt C++ classes are not wrapped. The main reason is that, since they are Qt classes, they would have to be wrapped with sip (for pyqt) or shiboken (for pyside) in order for them to be usable with pyqt/pyside. But at the same time, they would have to be wrapped with vtk’s own wrappers for them to be usable with other VTK classes. In other words, it’s logistically very complicated to wrap QtVTK classes in a way that would make them usable.

So when VTK and Qt are used from Python, the connections between VTK and Qt must be done through python and not through C++. That’s why classes like QVTKRenderWindowInteractor and packages like qml-vtk-python exist.

It’s very interesting that QVTKRenderWindowInteractor gives the same GLEW error. Can you post a bug report at https://gitlab.kitware.com/vtk/vtk with some details?

That was really very enlightening. Thanks! I thought this qml-vtk-python is an abstraction at a higher level…

Absolutely. I think i should write a more minimal example. So I will link it when done.

I posted it here. I hope i have done that correct to create a new issue? I never did a bug report here…
I also tried to sum the problem up on this branch, but there much more errors appear, which are not relevant for the main error i think:

2023-12-07 14:28:39.862 (   0.358s) [        D0ED9040]vtkOpenGLRenderWindow.c:704    ERR| vtkExternalOpenGLRenderWindow (0x2e78ec0): GLEW could not be initialized: Missing GL version
2023-12-07 14:28:39.982 (   0.479s) [        D0ED9040]   vtkShaderProgram.cxx:427    ERR| vtkShaderProgram (0x7f155c3af560): 1: #version 150
2: #ifndef GL_ES
3: #define highp
4: #define mediump
5: #define lowp
6: #endif // GL_ES
7: #define attribute in
8: #define varying out
9: 
10: in vec4 ndCoordIn;
11: in vec2 texCoordIn;
12: out vec2 texCoord;
13: void main()
14: {
15:   gl_Position = ndCoordIn;
16:   texCoord = texCoordIn;
17:   //VTK::TCoord::Flip
18: }

2023-12-07 14:28:39.982 (   0.479s) [        D0ED9040]   vtkShaderProgram.cxx:428    ERR| vtkShaderProgram (0x7f155c3af560): Could not create shader object.
2023-12-07 14:28:39.982 (   0.479s) [        D0ED9040]vtkOpenGLVertexArrayObj:255    ERR| vtkOpenGLVertexArrayObject (0x32b8190): attempt to add attribute without a program for attribute ndCoordIn
2023-12-07 14:28:39.982 (   0.479s) [        D0ED9040]vtkOpenGLQuadHelper.cxx:60    WARN| Error binding ndCoords to VAO.

For the bug report, I was looking for a bug report specific to QVTKRenderWindowInteractor, since it’s part of the VTK repository. I can take some of my time (probably this weekend) to run the QVTKRenderWindowInteractor to see if I can reproduce (and hopefully fix) the GLEW error that you saw there.

For qml-vtk-python, all I can offer is advice here in discourse, since qml-vtk-python isn’t part of VTK.

Oh that sounds great, thank you.
With the bugreport: I dont know how to get more relevant information for the QVTKRenderWindowInteractor. So do you think i should close / delete / change the bug-report?
I fully understand that i have to solve this problem in the qml-vtk-python project. I try to implement the code in my main application and hope that things get more clear and i can apply it to the project so that others can participate.

So i closed the issue in the bugtracker.

  • GLEW Error is gone when calling self.rw.OpenGLInitContext() on the renderWindow after creating the QOpenGLFrambufferObject.
  • vtkGenericRenderWindowInteractor can be used when setting
    self.rw.SetReadyForRendering(True)
    self.rw.SetIsCurrent(True)
    at the beginning of the render() method of the QQuickFramebufferObject.Render subclass

It is still not working in windows. But i think this is another issue.
Thank you once more @dgobbi