jspanchu/vtkGlfw

VTK adapter for DearImGUI

apaly opened this issue · 4 comments

apaly commented

Hi
Thank you for your contribution to VTK adapter for DearImGUI. I have been trying to implement a similar adapter for Nuklear which is another IMGUI using the mgui_impl_vtk.h and imgui_impl_vtk.cpp in your repo.

As far as I understand the code, vtkGenericOpenGLRenderWindow was used to render into a frame buffer. But I have not been able to figure out how and where one of these buffers g_FBOHdl = 0, g_RBOHdl = 0, g_TexHdl was bound to the vtkGenericOpenGLRenderWindow.

Could you please kindly help clarify how vtkGenericOpenGLRenderWindow renders into a frame buffer?

I would also appreciate any other information you can share.

apaly commented

Please accept my apology for using this repo. I could not reach you through the imgui-vtk repo.

Hello apaly. I'm sorry for the late reply. You can look at vtkDearImGUIInjector for updated usage of framebuffers

Could you please kindly help clarify how vtkGenericOpenGLRenderWindow renders into a frame buffer?

I would also appreciate any other information you can share.

By default, vtkOpenGLRenderWindow renders into a render buffer. This will be then blit into a write framebuffer. It is here that we take over and provide our own fbo. In a way, I tell vtkOpenGLRenderWindow to render into our fbo.

But I have not been able to figure out how and where one of these buffers g_FBOHdl = 0, g_RBOHdl = 0, g_TexHdl was bound to the vtkGenericOpenGLRenderWindow.

Here. As you see, it is not bound to the vtkGenericOpenGLRenderWindow. It is done in OpenGL. VTK will just use what's currently bound when BlitToCurrent = true.

As far as g_TexHdl, it is configured to be the color attachment for the framebuffer g_FBOHdl here.

Finally, as for g_RBOHdl, this is only necessary for depth information. It is configured like so here

Basically, a render buffer is easier to store per pixel information, imagine a real array. A framebuffer is what ends up on the screen. The framebuffer object in itself is like a struct with various attachments for color, depth, and stencil information.

There are two different things that can be done.

  1. Render VTK actors inside a DearImGUI window.
    This is implemented in imgui-vtk.
    For this to work, the typical approach is known as render-to-texture. It means exactly that. DearImGUI has a function to draw any supplied OpenGL texture handle as an image. (ImGui::Image(texId)...). So, create a texture, keep a reference to its handle. We'll also need a custom FBO to let VTK render its actors into our FBO. Configure the created texture as a color attachment to this FBO. Configure the renderbuffer as a depth attachment. Finally, right before making the render call to vtk, bind our framebuffer. That's all. Every time a resize occurs, adjust our texture and render buffer sizes..

  2. Ask VTK to render DearImGUI for us.
    This is implemented in vtkDearImGUIInjector.
    It is a more common use of DearImGUI. Here, use VTK's windowing system and the OpenGL context it sets up to draw ImGUI geometry. There is no need for a render-to-texture process. Instead, grab the renderwindow's fbo handle, bind it, make a call to ImGUI::RenderDrawData..

I know, very difficult to understand the first time.. :) Here are excellent resources if you wish to read on framebuffers, renderbuffers, textures and render-to-texture. 1, 2, 3, 4, 5