ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.85k stars 300 forks source link

ImGUI.Net with SFML.Net #195

Open Natlink opened 4 years ago

Natlink commented 4 years ago

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!

saffronjam commented 3 years ago

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!

Natlink commented 3 years ago

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 ;)

saffronjam commented 3 years ago

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( )

Natlink commented 3 years ago

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?

saffronjam commented 3 years ago

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.

Natlink commented 3 years ago

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

ghost commented 3 years ago

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

saffronjam commented 3 years ago

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).

ghost commented 3 years ago

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

justanobdy commented 2 years ago

Hello, does anyone know what happened to Saffron2D?

Natlink commented 2 years ago

@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 )

Thraka commented 1 year ago

@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

saffronjam commented 1 year ago

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 :)

Natlink commented 1 year ago

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

justanobdy commented 1 year ago

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