ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Interest in ImGui Backends wrappers

Open Refragg opened this issue 2 years ago • 7 comments

Hello, I've been interested to use this library for a bit with SDL and more particularly the SDL renderer.
I came to realize that there are no wrappers for the backends so i tried porting the C++ one but that didn't go so well. However, i just realized that this is using cimgui and cimgui does have an api for the backends.

So my question is: would you all be interested in wrappers for the backends in this library? It seems to me that it could have it's place here but be sure to tell me what you think

Refragg avatar Mar 31 '22 09:03 Refragg

If I understand correctly, ImGui.NET uses Veldrid as a backend, and you're proposing to add SDL support, correct? I am not an ImGui.NET dev, but as a long-time user of the C++ version, I think it makes total sense. That's the power of dear imgui, the ability to plug it into whatever platform you're currently working on.

benblo avatar May 09 '22 08:05 benblo

I think Veldrid is the only available implementation for ImGui.NET right now, i would ideally just want to be able to use the C++ backends directly by PInvoke or something, i did manage to have something working in the meantime but the problem is cimgui doesn't provide entry points for the backends as it does with all the ImGui stuff so i had to make modifications to cimgui's code in order for it to work and i also didn't do any code generation because i wanted to get something working and i haven't looked at how the code generation works

Refragg avatar May 09 '22 16:05 Refragg

You shouldnt need to modify cimgui: https://github.com/cimgui/cimgui/issues/157

sonoro1234 avatar May 10 '22 06:05 sonoro1234

Hello, i've tried looking at this way of doing it before but i don't know how this could be integrated for ImGui.NET since i don't think dotnet lets you directly just build cpp files and link against them but i might be wrong and it would be nice if you could prove me wrong

Refragg avatar May 12 '22 16:05 Refragg

They are cpp files with a C interface. The same as cimgui.

sonoro1234 avatar May 13 '22 05:05 sonoro1234

Hello, I am currently using ImGui.NET and SDL-CS in my project. It uses the SDL Platform and Renderer as a Dear ImGui backend. You can checkout the main integration implementation here: https://github.com/GaryHuan9/Echo/blob/c816c3ec4017a817ce23906b8029019cb5d8772e/Echo.UserInterface/src/Backend/ImGuiDevice.cs

GaryHuan9 avatar Jun 07 '22 03:06 GaryHuan9

@Refragg it is doable in couple steps you can see how it was done in those 2 forks. https://github.com/equilibrium-hub/ImGui.NET-nativebuild https://github.com/equilibrium-hub/ImGui.NET

  1. You need to pass the right backend flags to cimgui generator, it will output the right json definitions from luajit in cimgui\generator\.
  2. Alter CMakeLists.txt to include the source files for the backend of your choice, build the native library so the backend code is included in native cimgui library. Otherwise you will call Pinvoke C# methods but they would not exist in the native library. Make sure to link SDL libraries and include the SDL headers
#general settings
file(GLOB IMGUI_SOURCES
    cimgui.cpp
    imgui/imgui.cpp
    imgui/imgui_draw.cpp
    imgui/imgui_demo.cpp
    imgui/imgui_widgets.cpp
	imgui/backends/imgui_impl_sdl.cpp
	${TABLES_SOURCE}
)
  1. Copy the impl_definitions.json to CodeGenerator's definitions folder and tell it to use it here
  2. Build ImGui.NET and observe the bindings being generated for your backend.

image

EDIT:

For SDL backend you might need to patch the generated json definitions as they will generate SDL_Window structs and have conflicting names as members, for example event. See this diff You won't have to do it frequently as headers for backend implementations change once every 4-5 years

clibequilibrium avatar Jan 18 '23 01:01 clibequilibrium