# Offscreen Rendering with VTK 9.4, vtkXOpenGLRenderWindow warnings

**URL:** https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894
**Category:** Support
**Created:** [November 19, 2024, 5:06pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894 "2024-11-19T17:06:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![biagas](https://discourse.vtk.org/user_avatar/discourse.vtk.org/biagas/32/7380_2.png) [@biagas](https://discourse.vtk.org/u/biagas)
#### Post date: [November 19, 2024, 5:06pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894/1 "2024-11-19T17:06:59Z")

</div>

I pulled from the release branch yesterday (11-18) and compiled on linux. I didn’t modify any of the OpenGL build settings.

I then compiled the [OffscreenRendering example](https://examples.vtk.org/site/Cxx/Utilities/OffScreenRendering/) to test out how the runtime-choosing of render window type works.

When I run in batch nodes without X capability, I see this warning:  
`WARN| vtkXOpenGLRenderWindow (0x47f3b0): bad X server connection.`  
but the generated screenshot.png is correct, so the offscreen rendering appears to be working.  
I also modified the example to comment out the use of the vtkGraphicsFactory. It yielded the same results.  
Is there a way to avoid this warning when requesting offscreen rendering?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [November 19, 2024, 5:23pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894/2 "2024-11-19T17:23:45Z")

</div>

Hello @biagas

If the generated screenshot is correct, then there’s nothing to worry about. The warning message occurs when VTK is attempting to test whether it can access an X display. There are many reasons for being unable to use X/GLX so in the current version VTK prints them all as warnings. This is kind of helpful in understanding what the issue might be.

Right now, there is no way to avoid the warning. I could refactor it to output messages into a higher verbosity like `TRACE` or `vtkDebugMacro`.

---

<div class="post-metadata">

### Author: ![biagas](https://discourse.vtk.org/user_avatar/discourse.vtk.org/biagas/32/7380_2.png) [@biagas](https://discourse.vtk.org/u/biagas)
#### Post date: [November 19, 2024, 5:31pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894/3 "2024-11-19T17:31:16Z")

</div>

Thanks for the quick reply. I would upvote a move to vtkDebugMacro, just to prevent confusion for our users who would assume such a warning meant something is wrong.

---

<div class="post-metadata">

### Author: ![biagas](https://discourse.vtk.org/user_avatar/discourse.vtk.org/biagas/32/7380_2.png) [@biagas](https://discourse.vtk.org/u/biagas)
#### Post date: [November 19, 2024, 6:08pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894/4 "2024-11-19T18:08:41Z")

</div>

Sorry, another quick question. When offscreen rendering is chosen, why is the XOpenGL render window even considered?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [November 20, 2024, 2:57pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894/5 "2024-11-20T14:57:45Z")

</div>

> [@biagas](#):
>
> . I would upvote a move to vtkDebugMacro, just to prevent confusion for our users who would assume such a warning meant something is wrong.

Noted.

> [@biagas](#):
>
> When offscreen rendering is chosen, why is the XOpenGL render window even considered?

Right now, the options exposed by `vtkGraphicsFactory` class are not respected in the window selection process. The only way to make it bypass checks is to set the `VTK_DEFAULT_OPENGL_WINDOW` environment variable to `vtkOSOpenGLRenderWindow`.

I think we can revive `vtkGraphicsFactory` and make it work correctly.

---

<div class="post-metadata">

### Author: ![biagas](https://discourse.vtk.org/user_avatar/discourse.vtk.org/biagas/32/7380_2.png) [@biagas](https://discourse.vtk.org/u/biagas)
#### Post date: [November 20, 2024, 3:59pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894/6 "2024-11-20T15:59:52Z")

</div>

I apologize for not being clearer. I was asking about the use case where `vtkRenderWindow::OffScreenRendering` was set to true. This is how I am accustomed to requesting offscreen, not through the vtkGraphicsFactory. Possibly due to the gymnastics needed in the past to get a single build supporting onscreen, offscreen and headless modes.  
I don’t want to set `VTK_DEFAULT_OPENGL_WINDOW` to `vtkOSOpenGLRenderWindow` because that isn’t the mode I want to always use. I like the new runtime setup and am appreciative of the work that went into making it available. I was just curious why the `vtkXOpenGLRenderWindow` is tried when the vtkRenderWindow’s OffScreenRendering is requested.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [November 21, 2024, 3:42pm UTC](https://discourse.vtk.org/t/offscreen-rendering-with-vtk-9-4-vtkxopenglrenderwindow-warnings/14894/7 "2024-11-21T15:42:01Z")

</div>

Oh.

Since the runtime detection occurs while constructing an instance of `vtkRenderWindow`, the class cannot know if `OffScreenRendering` is going to be set or not. This could be solved if VTK C++ classes accepted constructor keyword arguments.

By the way, `OffScreenRendering` (which is deprecated in favor of `UseOffScreenBuffers` and `ShowWindow`) does not mean that VTK will never create a real window. It only means that the geometry will be rendered into a framebuffer which is not related to the window.

As you’re interested in programatically influencing the render window selection, it would be nice if we made use of `vtkGraphicsFactory::OffScreenOnlyMode`. Then you can benefit from the feature like this:

```cpp
vtkGraphicsFactory::SetOffScreenOnlyMode(true);
vtkNew<vtkRenderWindow> window;

```
