VTK rendering window doesn't display

Hello dear VTK people,

I have recently tried installing VTK 9.5 on Ubuntu 24.04 from source (latest .tar.gz release) but when I compile CylinderExample.cxx (from the VTK examples) the window doesn’t show up. I would like my vtk installation to use my Nvidia RTX 3060Ti GPU.

I use this command to compile :

g++ -g test.cpp -o test -I/usr/local/include/vtk-9.5 -L/usr/local/lib -lvtkCommonCore-9.5 -lvtkCommonDataModel-9.5 -lvtkCommonExecutionModel-9.5 -lvtkCommonColor-9.5 -lvtkFiltersSources-9.5 -lvtkRenderingCore-9.5 -lvtkRenderingOpenGL2-9.5 -lvtkRenderingFreeType-9.5 -lvtkRenderingUI-9.5 -lvtkInteractionStyle-9.5 -lvtkImagingCore-9.5 -lvtkIOImage-9.5 -lvtkjpeg-9.5 -lvtksys-9.5

I get no error, just nothing. Printing statements work if I add them though. I am also not experienced with building from source so this is what I did. I followed carefully the build.md of kitware (https://gitlab.kitware.com/vtk/vtk/-/blob/master/Documentation/docs/build_instructions/build.md).

For choosing the compile flag options I used the ninja “gui” generator making sure I allow OpenGL and basically leaving the default options, here is a bref summary of what seems important from the resulting CMakeCache.txt :

BUILD_SHARED_LIBS:BOOL=ON
VTK_DEFAULT_RENDER_WINDOW_OFFSCREEN:BOOL=OFF
VTK_DEFAULT_RENDER_WINDOW_HEADLESS:BOOL=OFF
VTK_GROUP_ENABLE_Imaging:STRING=YES
VTK_GROUP_ENABLE_Qt:STRING=NO
VTK_GROUP_ENABLE_Rendering:STRING=YES
VTK_GROUP_ENABLE_STANDALONE:STRING=YES
VTK_GROUP_ENABLE_StandAlone:STRING=YES
VTK_GROUP_ENABLE_Views:STRING=YES
VTK_INSTALL_SDK:BOOL=ON
VTK_OPENGL_HAS_EGL:BOOL=OFF # didn't remember this one was off i'll retry with ON
VTK_OPENGL_USE_GLES:BOOL=OFF  # i think it's for mobile dev
VTK_USE_CUDA:BOOL=OFF  # I just want to use the GPU for rendering, nothing more
VTK_USE_X:BOOL=ON  # i do have x11 and $DISPLAY -> :1
X11_X11_LIB:FILEPATH=/usr/lib/x86_64-linux-gnu/libX11.so # some similar entries with 'PATH NOT FOUND' but no compile error so I guess it's ok

Additional notes that might be useful :

  • running xeyes in the shell works.

  • I am not on Wayland (tried Ubuntu and GNOME desktop)

  • I tried some fiddling with Xauthority files

  • After recompiling in Debug, gdb indicates these adresses for renderer, renderWindow : 0x5555555a38a0, 0x5555555a9d80.

  • strace seems to show that every library he’s trying to use is found. I don’t see any error.

  • typeid of renderWindow gives : 15vtkRenderWindow.

  • I tried different build flags, some including VTK, Release mode, OPENGL_HAS_EGL without result.

  • The python works fine and allows me to render images using my GPU (I can know thanks to nvidia-smi)

Thank you for your help :slight_smile:

what does renderWindow->Print(std::cout) tells you ?

1 Like

That was fast :smiley:

Here is the output requested :
vtkRenderWindow (0x586d0a7a9d80)
Debug: Off
Modified Time: 388
Reference Count: 2
Registered Events: (none)
Erase: On
Window Name: Cylinder
Position: (0, 0)
Size: (300, 300)
Mapped: 0
ShowWindow: 1
UseOffScreenBuffers: 0
Double Buffered: 1
DPI: 72
TileScale: (1, 1)
TileViewport: (0, 0, 1, 1)
Borders: On
Double Buffer: On
Coverable: Off
Full Screen: Off
Renderers:
Debug: Off
Modified Time: 386
Reference Count: 1
Registered Events: (none)
Number Of Items: 1
Stereo Capable Window Requested: No
Stereo Render: Off
Point Smoothing: Off
Line Smoothing: Off
Polygon Smoothing: Off
Abort Render: 0
Current Cursor: 0
Desired Update Rate: 0.0001
In Abort Check: 0
NeverRendered: 1
Interactor: 0x586d0a7aa3e0
Swap Buffers: On
Stereo Type: RedBlue
Number of Layers: 1
AlphaBitPlanes: Off
UseSRGBColorSpace: Off
AnaglyphColorSaturation: 0.65
AnaglyphColorMask: 4 , 3
MultiSamples: 0
StencilCapable: False
PhysicalViewDirection: (0, 0, -1)
PhysicalViewUp: (0, 1, 0)
PhysicalTranslation: (0, 0, 0)
PhysicalScale: 1

This is unexpected, it should be either vtkXOpenGLRenderWindow or vtkEGLRenderWindow.

Can you try explicitely creating a vtkXOpenGLRenderWindow instead of a vtkRenderWindow ?

1 Like

So I added

#include <vtkXOpenGLRenderWindow.h>

And replaced :

vtkNew<vtkRenderWindow> renderWindow;

With :

vtkNew<vtkXOpenGLRenderWindow> renderWindow;

And now finally I see a window !

Unfortunately it’s completely black.

Other changes :

Type of renderWindow: 22vtkXOpenGLRenderWindow
vtkXOpenGLRenderWindow (0x5ba20faf2d40)

And I still have :

NeverRendered: 1

Something else must be going wrong, maybe @jaswantp has an idea.

1 Like

Try adding these lines to your test.cpp.

#include "vtkAutoInit.h"

VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingUI);
VTK_MODULE_INIT(vtkInteractionStyle);

When building with cmake, the module-level initialization of VTK’s class factories (for OpenGL etc) is automatic, but since you’re building without cmake, these extra lines of code are needed.

1 Like

Thank you very much, this solved my issue. I wasn’t aware of those differences between ninja builds and cmake builds, good to know !

Is it still a good idea to keep that instruction :
ccmake -GNinja ../path/to/vtk/source

in the official setup guidelines ?

In your original post, you said you were running g++ directly to build your program. That’s why VTK_MODULE_INIT is necessary.

It’s not about how VTK is built, it’s about how programs that use VTK are built.

So in the end it’s not a cmake vs ninja thing, or about anything on the “official setup guidelines” for building VTK. The ccmake -GNinja ../path/to/vtk/source example is still the best way to build VTK.