# Is it possible to use Makie in CImGui?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844>\
**Category:** New to Julia\
**Created:** [August 31, 2020, 3:13pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844 "2020-08-31T15:13:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [August 31, 2020, 3:13pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/1 "2020-08-31T15:13:24Z")

</div>

Is there a way to render with [Makie.jl](https://github.com/JuliaPlots/Makie.jl) directly into an existing OpenGL context?  
My goal is to render into a [CImGui.jl](https://github.com/Gnimuc/CImGui.jl) widget using Makie.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [August 31, 2020, 4:03pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/2 "2020-08-31T16:03:06Z")

</div>

I made a working example by hacking into GLMakie’s rendering loop last year, but it was buried in the Slack chat history. I just tried to cook up a new one, but Makie has evolved a lot since last year, it has too many abstraction layers, I don’t know where to start now.

If someone know how to get the `GLFW.Window` handle and corresponding OpenGL context from Makie’s `scene` object and how to insert custom functions into GLMakie’s rendering loop, then rendering CImGui’s widgets would be as simple as [this snippet](https://github.com/Gnimuc/CImGui.jl/blob/e43324e0fd36aeb7709dc653f2252d065ee341fa/examples/Renderer.jl#L29-L85).

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [August 31, 2020, 4:11pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/3 "2020-08-31T16:11:39Z")

</div>

Or the other way around, let Makie do the off-screen rendering, then re-render the output of framebuffer as an `CImGui.Image` object. This way is probably more feasible since Makie has some recording APIs around there.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 5, 2020, 12:56pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/4 "2020-09-05T12:56:16Z")

</div>

Thanks for the replies @Gnimuc!

I just had to replace one line in your gist file:

```julia
GLMakie.opengl_renderloop[] = imgui_renderloop

```

by

```julia
screen = AbstractPlotting.backend_display(GLMakie.GLBackend(), scene)
set_window_config!(renderloop=imgui_renderloop)

```

A few things are not working, but both display in one window!  
The mouse events are partially ignored by Makie or CImGui. (Makie ignores: Right mouse button; CImGui ignores: Mouse wheel, Keyboard, window close event)

(Here is the complete example: [Modification of Gnimuc's example: https://gist.github.com/Gnimuc/5a1e4942784cfc3558e2ee50b7bee84d · GitHub](https://gist.github.com/SteffenPL/88f65222bf786a6434bc2da3ae02ac74))

 ![Annotation 2020-09-05 135413](https://global.discourse-cdn.com/julialang/original/3X/5/3/53e38bd5a68ab002f4317406471327f3c92d2296.png)

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [September 5, 2020, 2:08pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/5 "2020-09-05T14:08:05Z")

</div>

> [@SteffenPL](#):
>
> A few things are not working, but both display in one window!  
> The mouse events are partially ignored by Makie or CImGui. (Makie ignores: Right mouse button; CImGui ignores: Mouse wheel, Keyboard, window close event)

Looks like there are some GLFW callback collisions. For example, Makie uses scroll callback to zoom in/out, but CImGui uses it for scrolling. CImGui’s callbacks can be overwritten via the following functions, not sure how to make them compatible with Makie’s callbacks though.

[https://github.com/Gnimuc/CImGui.jl/blob/master/src/backend/GLFW/callbacks.jl#L2-L5](https://github.com/Gnimuc/CImGui.jl/blob/master/src/backend/GLFW/callbacks.jl#L2-L5)

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 5, 2020, 2:25pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/6 "2020-09-05T14:25:25Z")

</div>

Thanks for the hints and also for the correction in the gist.

Do you know how to give CImGui priority? Can I let CImGui register the callbacks later than Makie?  
(For my case that would be sufficient, since I don’t need to interact with Makie too much.)

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [September 5, 2020, 3:17pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/7 "2020-09-05T15:17:37Z")

</div>

> [@SteffenPL](#):
>
> Do you know how to give CImGui priority? Can I let CImGui register the callbacks later than Makie?  
> (For my case that would be sufficient, since I don’t need to interact with Makie too much.)

I think it should work as long as CImGui registers callback functions later than Makie, the code linked below shows setting callbacks in GLFW is just a pointer swapping:

> <https://github.com/glfw/glfw/blob/0cc13ceafc233cb0bc95c8b3ff8152ee75893bf9/src/input.c#L875>

I don’t know when Makie registers its callbacks, so can’t tell much about that.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 5, 2020, 3:26pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/8 "2020-09-05T15:26:44Z")

</div>

Thanks!

Yes, it seems to work. If I create the CImGui context after setting up the Makie scene, then scrolling etc works which is all I need.

---

<div class="post-metadata">

**Author:** ![JamesNZ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jamesnz/32/35361_2.png) [@JamesNZ](https://discourse.julialang.org/u/JamesNZ)\
**Post date:** [July 29, 2024, 12:45pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/9 "2024-07-29T12:45:12Z")

</div>

I’ll sneakily necro this topic to say that we have (very experimental!) support for Makie in the latest release of CImGui: [Makie integration · CImGui.jl](https://gnimuc.github.io/CImGui.jl/stable/makie/)
