Black image when using offscreen rendering inside Qt application

I have written a library, which shall produce some rendering of scenes into images using VTK (no actual interactive 3D windows).

I have two executables from which the library is used: one command line tool and a Qt based GUI application. Using the library from the command line tool works all as expected. When called from the GUI application, the programm creates only a black image.

some more informations:

  • I use VTK8.2.0 (which comes along and is compiled together with Paraview 5.6)
  • Paraview was configured with these flags:
    -DCMAKE_BUILD_TYPE=Release
    -DPARAVIEW_BUILD_QT_GUI=OFF
    -DPARAVIEW_ENABLE_CATALYST=ON
    -DPARAVIEW_ENABLE_PYTHON=ON
    -DPARAVIEW_INSTALL_DEVELOPMENT_FILES=ON
    -DBUILD_TESTING=OFF
    -DVTK_OPENGL_HAS_OSMESA=ON
    -DVTK_USE_X=OFF
    -DVTK_DEFAULT_RENDER_WINDOW_OFFSCREEN=ON
    -DOPENGL_INCLUDE_DIR=IGNORE
    -DOPENGL_gl_LIBRARY=IGNORE
    -DOPENGL_xmesa_INCLUDE_DIR=IGNORE

Ok, I found that this issue is caused not by Qt but by some third library (OpenCASCADE). I’m investigating further.

I tried a lot of options/updates etc to nail this issue down but I could not finish it yet.

I currently reduced it to this: My Qt-application with an embedded OpenCASCADE-View-Widget runs ok. As soon as I add ${VTK_LIBRARIES} to the “target_link_libraries” statement in my CMakeLists.txt (without adding any code, that actually uses VTK), the application fails to run with an OpenGL issue.

VTK is detected by this statement:

find_package(VTK
    COMPONENTS
    FiltersCore
    FiltersGeneral
    FiltersSources
    FiltersGeneric
    FiltersExtraction
    FiltersPoints
    FiltersFlowPaths
    CommonCore
    IOLegacy
    IOGeometry
    IOExport
    IOImage
    IOXML
    ImagingCore
    RenderingOpenGL2
    RenderingAnnotation
     InteractionWidgets
     InteractionStyle
    REQUIRED
)

It looks like there is something implicitly initialized in one of the VTK libraries which causes trouble. What might this be?

I just updated to Paraview 5.8 with VTK-9. I still built it with OSMesa and offscreen rendering by default (actually I only want to do offscreen renderings with VTK).

Any ideas @ben.boeckel ?

This sounds like more of a question for @utkarshayachit or @ken-martin to me.

Hi, we had similar problems to this. I think it is related to OpenGL state. We resolved it by calling Render() at the right time. Try calling Render() before your scene rendering. We never figured out why this helped or what was wrong, but it worked…

Meanwhile, I’m wondering whether my dependency situation supposed to work at all or if it is expected to fail due to conflicts. I tried to sketch it here:


With OSMesa, problems occur in the GUI application, when the OpenCASCADE viewer is initialized.
I could make it work, if I build Paraview with “VTK_OPENGL_HAS_OSMESA” and “VTK_OPENGL_HAS_EGL” both set to “OFF”. Unfortunately, it does not work on a headless machine without “DISPLAY” variable then.

I’m a bit confused about the current state in Paraview. In earlier versions, I needed separate a build with OSMesa to enable headless operation. Recently, I read about switching between onscreen and offscreen rendering. But that does not include switching between hardware rendering and software OSMesa, right?

Thanks for any hint, Hannes

I’m wondering whether my dependency situation supposed to work at all

Your dependencies as you have shown in the diagram will not work since both Native-OpenGL and OSMesa define gl.... functions causing conflicts.

Recently, I read about switching between onscreen and offscreen rendering. But that does not include switching between hardware rendering and software OSMesa, right?

That is correct. For onscreen + offscreen to work in the same build, both configurations must use the same Mesa-based GL/rendering code.