# Rendering VTK in external OpenGL context with single buffering

**URL:** https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863
**Category:** Support
**Created:** [May 26, 2021, 8:24am UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863 "2021-05-26T08:24:11Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Carol\_Capek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/carol_capek/32/3451_2.png) [@Carol\_Capek](https://discourse.vtk.org/u/Carol_Capek)
#### Post date: [May 26, 2021, 8:24am UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/1 "2021-05-26T08:24:11Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)
#### Post date: [May 27, 2021, 5:10am UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/2 "2021-05-27T05:10:06Z")

</div>

You should be able to disable double buffering using [vtkWindow::SetDoubleBuffer](https://vtk.org/doc/nightly/html/classvtkWindow.html#ada827fc2e57d0c414514466005977c8c). By default, this is enabled by `vtkRenderWindow`.

---

<div class="post-metadata">

### Author: ![Carol\_Capek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/carol_capek/32/3451_2.png) [@Carol\_Capek](https://discourse.vtk.org/u/Carol_Capek)
#### Post date: [May 27, 2021, 6:34am UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/3 "2021-05-27T06:34:22Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![fab672000](https://discourse.vtk.org/user_avatar/discourse.vtk.org/fab672000/32/5808_2.png) [@fab672000](https://discourse.vtk.org/u/fab672000)
#### Post date: [October 6, 2022, 4:20pm UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/4 "2022-10-06T16:20:43Z")

</div>

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:

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

---

<div class="post-metadata">

### Author: ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)
#### Post date: [October 7, 2022, 1:41pm UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/5 "2022-10-07T13:41:13Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Carol\_Capek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/carol_capek/32/3451_2.png) [@Carol\_Capek](https://discourse.vtk.org/u/Carol_Capek)
#### Post date: [October 7, 2022, 2:34pm UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/6 "2022-10-07T14:34:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![fab672000](https://discourse.vtk.org/user_avatar/discourse.vtk.org/fab672000/32/5808_2.png) [@fab672000](https://discourse.vtk.org/u/fab672000)
#### Post date: [October 7, 2022, 5:02pm UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/7 "2022-10-07T17:02:13Z")

</div>

> [@sankhesh](#):
>
> @fab672000 Are you running into a similar issue?

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.

> [@Carol\_Capek](#):
>
> I will check my version again and upgrade if possible. Will keep you posted.

Thanks for providing feedback on this.

---

<div class="post-metadata">

### Author: ![Carol\_Capek](https://discourse.vtk.org/user_avatar/discourse.vtk.org/carol_capek/32/3451_2.png) [@Carol\_Capek](https://discourse.vtk.org/u/Carol_Capek)
#### Post date: [October 11, 2022, 7:43am UTC](https://discourse.vtk.org/t/rendering-vtk-in-external-opengl-context-with-single-buffering/5863/8 "2022-10-11T07:43:11Z")

</div>

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