pthom / imgui_bundle

Your fast track to powerful GUIs: Dear ImGui Bundle, an extensive toolkit for Python and C++ with immediate mode efficiency.
https://pthom.github.io/imgui_bundle/
MIT License
703 stars 73 forks source link

is it possible to render Panda3D context within Hello Imgui? (also moderngl) #253

Open tingspain opened 1 month ago

tingspain commented 1 month ago

Hello,

First of all, great job for the bundle. It is amazing.

I was wondering if it is possible to render Panda3D context within Hello ImGui, Kind of like matplotlib figures. I have been trying to achieve it but I was not lucky. I am newbie with Panda3D.

If it is possible, any hint?

Thanks In advance.

pthom commented 1 month ago

Hello,

First of all, great job for the bundle. It is amazing.

Thanks a lot, it is always nice to receive positive feedback!

I was wondering if it is possible to render Panda3D context within Hello ImGui, Kind of like matplotlib figures. I have been trying to achieve it but I was not lucky. I am newbie with Panda3D.

If it is possible, any hint?

I am not familiar at all with Pandas3D. Based on what I've quickly found, It is a full engine for realtime 3D game.

Given this, there are two possible directions, which depends on a choice you have to make by answering this question: who is responsible for creating and handling the main app window, and handling events (mouse, keyboard, etc)?

If Dear ImGui Bundle is responsible for creating the main window

In that case, you would need to:

  1. have a way to render Pandas3D to a frame buffer, and use this frame buffer as the background of your application.
  2. have a way to transmit all needed events from ImGui to Pandas3D

Please note that in this case you would be using the standard rendering of ImGui Bundle (provided by HelloImGui). It uses OpenGL3 and glfw and this cannot be changed.

As far a 1. (Render Pandas3D to a frame buffer) is concerned, here is see an example where the background is provided by an OpenGL shader:

As far as 2. (transmit events to Pandas 3D) is concerned, you might interrogate imgui.get_io() to get info about the events.

If Pandas3D is responsible for creating the main window

In that case

you will need to integrate ImGui inside pandas3D: this means that you will need to:

  1. manually render ImGui's "DrawData". For a C++ example you can look at panda3d_imgui and especially this part https://github.com/bluekyu/panda3d_imgui/blob/e42a14c62b4ee7c59871f73fc41e2a4e45d6ae51/panda3d_imgui/panda3d_imgui.cpp#L358-L437

  2. Transmit events from Pandas3D to ImGui when needed

You may take some inspiration from some existing pure python backends, available here


At a first glance, it is not a very easy endeavor. Anyhow, good luck, and keep me informed if you make progress in either direction!

tingspain commented 1 month ago

First of all, @pthom, thank you for your prompt response.

I am aiming to achieve the first option: rendering Panda3D within Hello_Imgui. You've done an outstanding job incorporating a variety of functionalities into the bundle, such as viewports, imPlot, and ImNodes, which has saved me a significant amount of work.

That being said, I am looking to integrate a graphics engine like RenderPipeline, which is based on Panda3D, into your bundle. While I am actively exploring ways to accomplish this, I haven’t yet found a straightforward method for integrating Panda3D. I’ll continue my efforts and will share any progress in this thread.

Additionally, I have a question: would it be possible to use ModernGL with your bundle?

Thanks in advance for your help!

pthom commented 1 month ago

would it be possible to use ModernGL with your bundle

I know that some people tried, but they did have to render from Python.

On my side I did not use ModernGL, So I don't know what is possible. Anyhow, I think that if you are rendering with modernGL to a texture, you could then use this texture in imgui bundle.

pthom commented 1 month ago

Keep me posted about your progress, I am interested!

Tremeschin commented 1 month ago

In my case, I'd like to do kind of the opposite with ModernGL,

I'm already too deep with the glfw package and the moderngl_window's classes in my code, and would like to see an integration directly of imgui_bundle how's it currently done in mgl [1] [2], drawing on top of a fbo currently in use

I'll tackle on this eventually per https://github.com/BrokenSource/ShaderFlow/issues/6, as imgui is holding me on cp311. But the linked PRs and resources here smells good to me on it being possible, perhaps we/I can make the integration official!

I'm really looking forward to use your package for the future!

pthom commented 1 month ago

@Tremeschin

I originally worked and contributed to pyimgui (which you mentioned), before developing imgui bundle. So the API of both are very similar, except that ImGui bundle bindings are auto-generated (and thus maintenable and maintained) documented, and include lots of other libraries.

Again, you can take inspiration from the pure python backends. Important note: the pure python backend are adapted from the originals from pyimgui (they were a bit modernized, but they remain very close)

I'm really looking forward to use your package for the future!

Welcome to the community! I do like the motto of your project (" Imagine ShaderToy, on a Manim-like architecture"), and I'm interested in it. If possible, please keep me informed of the status here, or post updates in the gallery.

Tremeschin commented 1 month ago

Welcome to the community! (...) and I'm interested in it (...) updates in the gallery

Thanks @pthom, happy to get into the community! These resources will also definitely help 🙂

It'll be first used as an internal GUI for controlling actions inside the scene, states, dev menus, switching scenes in real time. But it might expand to more advanced stuff in the future, like rendering options within, potential use for basic games or interactive demos. Whenever I have something worthy I'll surely add to the gallery

Humbly linking DepthFlow, given your interest on the parent project! Much more traction, and a actual final product. Will be the first to receive any GUI :)

Tremeschin commented 1 month ago

A, someone beat me to it in PR https://github.com/moderngl/moderngl-window/pull/197 (unmerged), I had a local version which was rendering correctly just needed to proxy the events to your package, can confirm it was very easy to convert the code and worked pretty much flawlessly in my code base with moderngl 🙂

pthom commented 4 weeks ago

@Tremeschin : I tried https://github.com/moderngl/moderngl-window/pull/197, and it works fine. Thanks for the info