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

**URL:** https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848
**Category:** Support
**Tags:** python
**Created:** [December 5, 2023, 10:43am UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848 "2023-12-05T10:43:31Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 5, 2023, 10:43am UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/1 "2023-12-05T10:43:31Z")

</div>

I tried to update this [QML-VTK project](https://github.com/dao-duc-tung/qml-vtk-python) from Dao Duc Tung to the current vtk 9.3.0 & PySide6 versions [fork](https://github.com/NewPony007/qml-vtk9-python310-PySide6).  
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!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 5, 2023, 2:03pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/2 "2023-12-05T14:03:59Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/-/blob/v9.2.6/Rendering/External/Testing/Cxx/TestGLUTRenderWindow.cxx) in C++.

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 5, 2023, 3:51pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/3 "2023-12-05T15:51:01Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/-/blob/v9.2.6/Rendering/External/Testing/Cxx/TestGLUTRenderWindow.cxx) 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!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 5, 2023, 4:13pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/4 "2023-12-05T16:13:34Z")

</div>

To build the GLUT test, you need to create a new CMakeLists.txt for it (see the [VTK C++ examples](https://examples.vtk.org/site/Cxx/GeometricObjects/CylinderExample/)). 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.

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 5, 2023, 5:24pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/5 "2023-12-05T17:24:44Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/-/blob/v9.2.6/Rendering/External/Testing/Cxx/TestGLUTRenderWindow.cxx), 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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 5, 2023, 5:50pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/6 "2023-12-05T17:50:30Z")

</div>

> [@NewPony](#):
>
> 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?

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?

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 5, 2023, 8:33pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/7 "2023-12-05T20:33:33Z")

</div>

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()](https://doc.qt.io/qtforpython-6/PySide6/QtQuick/QQuickWindow.html#PySide6.QtQuick.PySide6.QtQuick.QQuickWindow.beginExternalCommands) and [endExternalCommands()](https://doc.qt.io/qtforpython-6/PySide6/QtQuick/QQuickWindow.html#PySide6.QtQuick.PySide6.QtQuick.QQuickWindow.endExternalCommands). But also no luck when comment that out or replacing here.

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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 6, 2023, 1:57pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/8 "2023-12-06T13:57:23Z")

</div>

There might be some useful information in the source code for [QtQuickVTKRenderWindow](https://gitlab.kitware.com/vtk/vtk/-/blob/release/GUISupport/QtQuick/QQuickVTKRenderWindow.cxx) in VTK. I notice that it has some code that is specifically for Qt 6.

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 6, 2023, 4:13pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/9 "2023-12-06T16:13:35Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 6, 2023, 4:35pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/10 "2023-12-06T16:35:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 6, 2023, 4:50pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/11 "2023-12-06T16:50:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 6, 2023, 5:24pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/12 "2023-12-06T17:24:54Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk) with some details?

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 6, 2023, 7:42pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/13 "2023-12-06T19:42:30Z")

</div>

> [@dgobbi](#):
>
> 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.

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

> [@dgobbi](#):
>
> It’s very interesting that `QVTKRenderWindowInteractor` gives the same GLEW error. Can you post a bug report at [https://gitlab.kitware.com/vtk/vtk](https://gitlab.kitware.com/vtk/vtk) with some details?

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

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 7, 2023, 1:07pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/14 "2023-12-07T13:07:15Z")

</div>

> [@dgobbi](#):
>
> Can you post a bug report at [https://gitlab.kitware.com/vtk/vtk](https://gitlab.kitware.com/vtk/vtk) with some details?

I posted it [here](https://gitlab.kitware.com/vtk/vtk/-/issues/19190). 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](https://github.com/NewPony007/qml-vtk9-python310-PySide6/tree/minimal), but there much more errors appear, which are not relevant for the main error i think:

```auto
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.

```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [December 7, 2023, 2:23pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/15 "2023-12-07T14:23:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 7, 2023, 2:42pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/16 "2023-12-07T14:42:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![NewPony](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newpony/32/7846_2.png) [@NewPony](https://discourse.vtk.org/u/NewPony)
#### Post date: [December 12, 2023, 1:48pm UTC](https://discourse.vtk.org/t/getting-error-glew-could-not-be-initialized-missing-gl-version/12848/17 "2023-12-12T13:48:18Z")

</div>

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
