xposure / ImGuiSharp

MIT License
12 stars 2 forks source link

MonoGame rendering #1

Open drakbar opened 7 years ago

drakbar commented 7 years ago

Hello @xposure,

I am really interested to know how you achieved this. I understand that you ported the Dear ImGui to C#, and I am not sure if you have completed this process.

I have been using ImGui.NET to get a hold of the data. However, I wasn't quite sure how to feed that information into MonoGame, and I have used your code as a guide on how to achieve it. Here it a shot of what it looked like.
gui

It's something, but not what I am going for. Thanks for any help!

xposure commented 7 years ago

The screen shot you linked to is definitely my code running ported to c# and not using any ImGui bindings. The code is in ImGui.MonoGame.NET and the other projects in this repo were from when I was attempting to clean up the code and make it more C# based.

To answer your question I'm not entirely sure what is going on, perhaps you haven't setup the Display size properly?

            // Application init
            io = ImGui.Instance.GetIO();
            io.DisplaySize.x = GraphicsDevice.Viewport.Width;
            io.DisplaySize.y = GraphicsDevice.Viewport.Height;

The block filled text also indicates that the texture isn't bound correctly to the shader and its rendering a pure white texture instead.

That all being said I just recently started getting back in to this code base and looking at finishing it, its about 95% done if not more with one or 2 random bugs.

drakbar commented 7 years ago

First off I just ran your updated repo, and I works out of the box with one exception(the one you noted). When I tried to build it the target was set to x64, once I changed that it worked without a hitch.

I am not surprised that my original approach(shown in the picture above) had some faults. Thank you for doing this!

EDIT Working like a charm!! gui1

xposure commented 7 years ago

You can build for x64 or x86 if you manually edit the nuget package for SharpFont.Dependencies in packages\SharpFont.Dependencies.2.6\build\SharpFont.Dependencies.props and change it to msvc12\$(PlatformName) instead of msvc10\x86

drakbar commented 7 years ago

@xposure, so I noticed that the load and save settings functions for the ini file were not implemented, and so I took the liberty to write them. Here is the code.

There are some notes and issues concerning it:

  1. I am not sure where or if you are using (no pun intended) directives but this does require System.IO.
  2. Because SaveSettings is a static function I passed ImGuiState as a parameter which changes line 3345 in ImGui.cs to SaveSettings(g), I am not sure about line 380. I know its meant to save the setting after a arbitrary amount of time, but I am unsure of what you were doing there.
  3. In SaveSettings the check to see if the window flag (to not save the settings) is set, appears to me to be unnecessary since I don't think you can create a window with flags, however, I may be wrong.
  4. In LoadSettings the blocks for loading position and size are almost identical, I would have liked to make a lambda though I am not sure about C# lambdas.
  5. In order for SaveSettings to be called, I made Shutdown public and call it in UnloadContent.
  6. The game crashes when trying to double click the window to collapse it, and if you change the value of collapse in the ini file to True. I am sure it has to do with a flag somewhere.

I have tested it and it does indeed work, saving to disk and loading from it. Also, changing position and size values in the ini file does reflect change in game. Let me know your thoughts and possible changes about integration.

xposure commented 7 years ago

Long story short it seemed like this wasn't a welcome addition over at the DearImGui repo so I stopped working on this code base for the public. The creator felt it made more sense to just use the bindings to C rather than a real port so that multiple code bases didn't have to be maintained.

I tried to use the bindings on several occasions (2 different versions) and it felt incomplete and annoying to work with and P/Invoke overhead can add up. One thing I dislike is that its basically a singleton, the version I use for a closed source project has no singletons what-so-ever and I can have multiple instances running of DearImGui which helps when you are doing things like in-game editors (aka Unity style).

I would welcome any PRs and if this does indeed seem to be something people are interested in, I could start maintaining it and keeping it up to date.

Note: I was trying to keep the code as close to 1-to-1 conversion as possible with the exception of pointers so that integrating DearImGui commits would be straight forward

drakbar commented 7 years ago

@xposure, I sorta got that feeling from what I read in the threads over there. However, it is under MIT license, and correct me if I am wrong but that means its open for any type of use. Having said that, I attempted at using the other as well and I wasn't successful, hence my first post here.

I was not aware that there was an overhead associated with P/Invoke, granted I have only know about it for a few days, but that makes it more sensible to port it. Albeit, it maybe a little more work than just putting a wrapper around it.

As, far as a pull request is concerned I would gladly submit one. I am just a student, but many of my buddies at school would probably love to know that this is available.

I was aware that you wanted to stay true to the original code base as possible, and personally all I did was write the commented code as close that I could. Accessing the filestream was probably where I got off base a little bit, the rest of the 'major' deviations was just so that I could debug it. In fact I was hoping you had a better idea on how to get it back in line.

xposure commented 7 years ago

P/Invoke has about 30-40 instruction overhead which can be reduced with some attributes like SuppressSecurity but then there is marshaling of data for types that aren't blitable. Its almost not even measurable if you are making 5 calls a second, but can start to add up if you make 100s or 1000s.

I think what I will start to do is spend some time each night to bring the code base up to date and implement a few odds and ends I left out as well as add some additional renderers.

drakbar commented 7 years ago

I showed this off to my friends and they were ecstatic. The were asking how they could get this in their projects.

hawaii

This is pretty mundane, nothing flashy here, but people do care about the work you have already invested. Thats my 2 cents for today.

xposure commented 7 years ago

Just a heads up, will take a look at save/loading in the next week or so.