# Integrate VTK inside egui

**URL:** https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662
**Category:** Support
**Tags:** code
**Created:** [May 22, 2025, 9:08pm UTC](https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662 "2025-05-22T21:08:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Gerharddc](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/8e8cbc/32.png) [@Gerharddc](https://discourse.vtk.org/u/Gerharddc)
#### Post date: [May 22, 2025, 9:08pm UTC](https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662/1 "2025-05-22T21:08:40Z")

</div>

Hi, I am trying to use VTK to create custom widgets for use with egui.rs. To do so I have tried combining the egui example for custom OpenGL widgets at [egui/examples/custom\_3d\_glow/src/main.rs at main · emilk/egui · GitHub](https://github.com/emilk/egui/blob/main/examples/custom_3d_glow/src/main.rs) with the VTK external rendering example/test at [https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/External/Testing/Cxx/TestGLUTRenderWindow.cxx](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/External/Testing/Cxx/TestGLUTRenderWindow.cxx). I have placed the proof-of-concept code I have so far at [GitHub - Gerharddc/egui-vtk](https://github.com/Gerharddc/egui-vtk). Currently the example only works on Windows but adapting it for Linux should just require minor CMake adjustments.

So far I have managed to get something that compiles and runs but unfortunately the VTK widget is just black as shown below:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/4/4d6052490e43f96e0e321e5bc878ad12232a2019.png)

I am also hit with a ton of errors similar to:

`2025-05-22 23:02:07.188 ( 20.377s) [6F24EB89BD0D50E2]vtkOpenGLRenderWindow.c:286 WARN| . . GL Message: id=1005 source=SOURCE_API(0x8246) type=ERROR(0x824c) severity=HIGH(0x9146) message=No detailed debug message due to a non-debug context`

 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/8e7d0f82917deeb4c1f30ddf941688709367ff77.png)

The are many of these for each render pass. And after checking with the debugger, it seems the log at vtkOpenGLRenderWindow.c:286 is the result of various different OpenGL calls so I suspect this is a general issue with the OpenGL integration.

Unfortunately I have no idea where to go from here as that is about all the information I have. I really expected this to work once it compiled + ran without crashing since the egui part should be making the OpenGL context active right before calling render on VTK and my impression is that with the external renderer, this is what VTK expects.

Any ideas?

---

<div class="post-metadata">

### Author: ![Gerharddc](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/8e8cbc/32.png) [@Gerharddc](https://discourse.vtk.org/u/Gerharddc)
#### Post date: [May 24, 2025, 10:36am UTC](https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662/2 "2025-05-24T10:36:54Z")

</div>

I still don’t have things working with egui yet, but egui uses glow at the lower level (at least with its default “eframe” integration) and I now have integration directly with glow working on [GitHub - Gerharddc/egui-vtk at glow](https://github.com/Gerharddc/egui-vtk/tree/glow).

It turns out the warnings were caused by `.with_profile(GlProfile::Compatibility)` not being passed during context creation as it seems VTK relies on this.

Another important factor to get VTK things visible was to call `gl.clear(COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT);` before calling the VTK render function. Clearing only `COLOR_BUFFER_BIT` seems to be insufficient.

I also implemented a way to use `gladLoadGL` instead of `gladLoaderLoadGL` to ensure that the exact same OpenGL functions are loaded on the C++ as on the Rust side, but so far this does not seem to be critical to get things working. It might help to avoid nasty issues on other platforms though.

---

<div class="post-metadata">

### Author: ![Gerharddc](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/8e8cbc/32.png) [@Gerharddc](https://discourse.vtk.org/u/Gerharddc)
#### Post date: [May 24, 2025, 3:23pm UTC](https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662/3 "2025-05-24T15:23:03Z")

</div>

![image](https://discourse.vtk.org/uploads/default/original/2X/6/681e7c445c4083da939307e2040d7351326d63d6.png)

Ok so I finally got this working! In the end I had to resort to rendering VTK inside an offscreen FBO and piping its texture into an egui Image. I actually managed to get VTK drawing without that, but it refused to draw in the correct place for some reason. It drew with the correct size at least though. Anyway, this is probably a nicer approach anyway as it saves VTK from having to redraw for every frame.

Now the last remaining challenge is to get mouse events forwarding…

---

<div class="post-metadata">

### Author: ![Gerharddc](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/8e8cbc/32.png) [@Gerharddc](https://discourse.vtk.org/u/Gerharddc)
#### Post date: [May 25, 2025, 4:12pm UTC](https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662/4 "2025-05-25T16:12:09Z")

</div>

Mouse integration is also working now! I have uploaded the final code to [GitHub - Gerharddc/vtk-egui-demo: Simple demo integrating VTK with egui/eframe](https://github.com/Gerharddc/vtk-egui-demo).

![Demo](https://discourse.vtk.org/uploads/default/original/2X/7/7e5c3d7241c801f4ce926a9c32d9cbc7b1a05bf5.gif)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [May 26, 2025, 7:59am UTC](https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662/5 "2025-05-26T07:59:47Z")

</div>

Awesome work @Gerharddc , thanks for sharing!

---

<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: [May 26, 2025, 3:05pm UTC](https://discourse.vtk.org/t/integrate-vtk-inside-egui/15662/6 "2025-05-26T15:05:17Z")

</div>

Cool work @Gerharddc ! It is interesting to get vtk render interactively inside an external GUI.
