Rendering VTK in external OpenGL context with single buffering

Hi All!

I want to render a circle (to start off slow) using VTK in an existing application. We use GLFW to create a window and the OpenGL context as well as GLAD for the bindings. I presume that vtkExternalOpenGLRenderWindow would be the tool to use in this case.

After some successful experiments I found a problem I cannot solve: Our application uses single buffering (hard requirement) and additionally we want to render VTK into a FBO, for a later use/composition. The problem I ran into is that the circle is rendered but VTK attempts to bind GL_BACK_LEFT to the DrawBuffer and ReadBuffer, which does not exist in our context and the debug callback reports it as an error. I am concerned about stability implications of our application under these circumstances, and I wonder if there is a better way to embed VTK into a pre-existing single-buffer OpenGL context.

Any help is much appreciated!

You should be able to disable double buffering using vtkWindow::SetDoubleBuffer. By default, this is enabled by vtkRenderWindow.

Thanks @sankhesh for your tip! Unfortunately, I already use this flag with no affect. When looking into the source code I can see, that the DoubleBuffer flag is not used to check if the buffers are there in the initialization of the vtkOpenGLState object.

Could it be that this is a bug?

Is it possible that calling SetDoubleBuffer() earlier would work : e.g. just after in your vtkRenderWindow instance construction ?

Here’s the code I got from a quick look to 9.2.2 sources and I can read:

vtkRenderWindow::vtkRenderWindow()
{
  this->DoubleBuffer = 1;
}

So I would try to set it (using the wrapping set function SetDoubleBuffer() ) just after my smartPointer allocation of the vtkRenderWindow object that should call this constructor ?

I believe the original issue of looking at DoubleBuffer when initializing vtkOpenGLState has already been fixed. @Carol_Capek could you confirm?

@fab672000 Are you running into a similar issue?

I actually never got it to run. I went for a rather hacky solution where I use an offscreen context, without error propagation, besides my main context.

I tried to look into the code again today, but i couldn’t wrap my head around it again in a meaningful time. I will check my version again and upgrade if possible. Will keep you posted.

No as using double buffering does not cause me issues and allows for faster fps at this time, but using opengl acceleration too, I was just interested by this issue.

Thanks for providing feedback on this.

Following up: I tried the new version 9.2.2 and apparently the bug is gone. Thanks for letting me know @sankhesh !

1 Like