pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
604 stars 91 forks source link

Custom drawing behind GUI not possible due to Impl_Frame_3D_ClearColor() #70

Closed wkjarosz closed 7 months ago

wkjarosz commented 7 months ago

Thanks for the great framework.

It would be useful to be able to draw the GUI elements on top of my own custom 3D drawing. Unfortunately, this doesn't seem to be possible, even if I select ProvideFullScreenDockSpace or NoDefaultWindowEven. Even if I put some custom 3D OpenGL drawing into my ShowGui callback, the screen is cleared at abstract_runner.cpp:593 via a call to Impl_Frame_3D_ClearColor(). Simply commenting out this line would allow me to draw content behind any generated ImGui windows, which seems like a common use-case.

I'm happy to provide a pull request with a change, depending on how you would like to have this implemented. One possibility: add a flag in one of the param structs to make clearing the screen optional. If clearing is disabled, the user can still clear (and draw anything they want below the gui elements) in their ShowGui function.

pthom commented 7 months ago

Hello,

Thanks for contacting me! I'd be very happy to accept a PR!

I'm not sure that ShowGui is the ideal place where to place such code, since the background drawing in not really related to the GUI.

After a quick look, I though it would perhaps be better to add custom callback inside src/hello_imgui/runner_callbacks.h near existing ones:

For example:

    VoidFunction PreNewFrame = EmptyVoidFunction();
    VoidFunction BeforeImGuiRender = EmptyVoidFunction();
    VoidFunction AfterSwap = EmptyVoidFunction();

   // add this?
  VoidFunction CustomBackground = EmptyVoidFunction();

Note:

What do you think?

PS:

I like your hdrview project! It made me think of another project I wrote ImmVision, (part of "ImGui Bundle") although it does not handle hdr (it is more of an image processing debugger).

wkjarosz commented 7 months ago

Yes, that does sound like a better way to fit it in. I'll give it a try and let you know.