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

ImGUI.Net with SFML.Net

Open Natlink opened this issue 4 years ago • 15 comments

Solution in the last comments above

Hi, They seems to have an issue when using ImGui.NET with the default port of SFML to C# I have tried almost everything ( API calls order, ect ), but nothing seems to work. Each time i used an api call of ImGUI.NET in my program, i get a segFault ( AccessViolationException ). I think it's caused by the fact that the SFML window is not "linked" to ImGUI, but i can't figure out how to do that.

I know ImGUI can work with SFML, ImGUI and SFML can work in c#, the question is did they can work together in c# version.

If someone have find a solution, or have an idea on what's going on, i will like it!

Natlink avatar Sep 01 '20 19:09 Natlink

Hi,

I have got SFML.Net to work with ImGui.Net to about 99% (currently come problems with dockspace).

What you need to do is look how eliasdaler wrote the backend (https://github.com/eliasdaler/imgui-sfml and imgui-SFML.cpp) and translate it to C#. Though, I had to create my own DLL written in C++ for the "RenderDrawLists", as I could not figure out how to translate the OpenGL code in that function. I uploaded this as a separate package on nuget: Saffron.Util.ImGuiSFML.

The DLL in the nuget package only export one function, "RenderDrawLists", that takes the ImDrawData and ImGuiIO as parameters. But using my translation and installing the package should make it work for you.

My translation is definitely not perfect as I am new to C#, but check it out: GuiImpl.zip

At line 251 I import from the dll that in the nuget package.

Hope it helps!

saffronjam avatar Dec 16 '20 17:12 saffronjam

HI! thanks for your answer, i didn't except any after all this time :) I will try your solution. Just a thing, your uploaded zip is flaged as dangerous by firefox so take care ;)

Natlink avatar Dec 25 '20 18:12 Natlink

Cool! You can checkout my repo, Saffron2D (https://github.com/saffronjam/Saffron2D), if you need more hints. It could differ slightly from the file I uploaded.

But the backend works like any other imgui-backend. Initialize first, then call a function before every frame and another function after every frame is done.

In this case it should be: Initialize with GuiImpl.Init( ) Before each frame call: GuiImpl.Update( ) After each frame call: GuiImpl.Render( )

saffronjam avatar Dec 25 '20 19:12 saffronjam

I have checked this, it's a nice exemple pf sample code for the using of imgui and sfml. Thanks for your help, it should be good for me now Any idea why windows warn me about your zip?

Natlink avatar Dec 25 '20 20:12 Natlink

Good to hear, happy to help :)

I don't know why you are getting the warning, and it's strange because it contains a single source file and nothing more. I tried to replicate it myself with other browsers on different machines but I don't get any warning at all.

saffronjam avatar Dec 25 '20 20:12 saffronjam

Yeah i see that after downloading it on linux, really strange .. All seems ok, now! Thanks for your help For futur view:

  • Get nuget SFML.net, IMGUI.net
  • Implem or get here
  • Add the hooked DLL from nuget Saffron.Util.ImGuiSFML
  • Enjoy imgui with SFML in .net ! image

Natlink avatar Dec 26 '20 21:12 Natlink

Hi,

I have got SFML.Net to work with ImGui.Net to about 99% (currently come problems with dockspace).

What you need to do is look how eliasdaler wrote the backend (https://github.com/eliasdaler/imgui-sfml and imgui-SFML.cpp) and translate it to C#. Though, I had to create my own DLL written in C++ for the "RenderDrawLists", as I could not figure out how to translate the OpenGL code in that function. I uploaded this as a separate package on nuget: Saffron.Util.ImGuiSFML.

The DLL in the nuget package only export one function, "RenderDrawLists", that takes the ImDrawData and ImGuiIO as parameters. But using my translation and installing the package should make it work for you.

My translation is definitely not perfect as I am new to C#, but check it out: GuiImpl.zip

At line 251 I import from the dll that in the nuget package.

Hope it helps!

In C#, you can use OpenTK to use OpenGL calls

ghost avatar Dec 31 '20 19:12 ghost

I am sure this is possible, and I tried using OpenTK. The problem I encountered was that OpenTK required an active graphics context, which I was unable to create.

Why? Well, I have only really used SFML with C++ where any GL-calls is pretty much built in within one header. Apart from that I am not very familiar with OpenGL.

So if anyone is familiar with OpenTK, it is definitely worth to fix this, so that we can write a single SfmlBackend.cs (to maybe even feature in the ImGui.NET repository, just like cpp ImGui does with its folder backends) with no extra fuss (like the dll).

saffronjam avatar Dec 31 '20 20:12 saffronjam

I think you need to create an instance of GameWindow before using OpenGL. There is an example here

ghost avatar Dec 31 '20 21:12 ghost

Hello, does anyone know what happened to Saffron2D?

justanobdy avatar Jul 10 '22 16:07 justanobdy

@saffronjam any chance you still have the original cpp file you compiled in the dll (who's still available here as nuget package ? https://www.nuget.org/packages/Saffron.Util.ImGuiSFML )

Natlink avatar Aug 18 '22 10:08 Natlink

@justanobdy I think it was deleted. It looks like @saffronjam went full C++ however someone was able to copy the code before that happened. I suggest you fork this repo so you have a copy. https://github.com/PascalPieper/Portfolio_TileGame/blob/110f063db8ccea7484266b7e110d9d68298ca4eb/TileGame/Utility/SfmlExtension/GuiImpl.cs

Thraka avatar Nov 22 '22 21:11 Thraka

The project was accidentally deleted when cleaning some other project, which is a shame. I've been meaning to take a look at it again to make it work, but haven't had the time. @Natlink Unfortunately I don't have the cpp-file either since I never thought anyone would use this, I will come back once I have looked at it :)

saffronjam avatar Nov 22 '22 21:11 saffronjam

Ok, thanks for your answer ! It will be incredible if you could find Time/motivation to found / re-write it!

Natlink avatar Nov 22 '22 22:11 Natlink

No worries, I've also taken the same route, and switched to C++ for my projects. Thanks!

justanobdy avatar Nov 23 '22 00:11 justanobdy