Skip to content

aybe/DearImGui

Repository files navigation

DearImGui

This is imgui and implot bindings for .NET, including a controller for OpenTK.

Features

  • Original documentation, when present, is available through IntelliSense
  • Friendly types when possible: Span<T>, vectors from System.Numerics
  • Close to zero allocations, the garbage collector will be your best friend!

Getting started

Windows, AnyCPU, .NET 6.0, OpenGL 4.5:

Nuget Nuget Nuget

You will also need Microsoft Visual C++ Redistributable latest supported downloads:

Should you need debug builds of native DLLs, you will find them in the Releases tab.

Getting started (development)

General notes

Unlike similar projects, this one is generated directly against sources.

The pros of this approach are, for instance:

  • documentation (when there is) for pretty much every member out there
  • default values for optional parameters, i.e. 'vanilla' imgui interface

In short, we can closely mimic the interfaces of the original projects.

But there are cons as well, for instance:

  • the generated code is better but the generators are more complex
  • DLL exports with decorated names as these differ in 32-bit VS 64-bit

The former was solved by spending quite some time polishing the generators.

The latter was solved using Roslyn, rewriting the entire output to be AnyCPU.

Cloning

The repository has submodules, don't forget to clone them in the process:

git clone --recurse-submodules https://github.com/aybe/DearImGui.git

Building

In order for the projects in Managed folder to build, there are implicit dependencies:

  • projects in Generated folder shall be started at least once
  • projects in Native folder shall be batch built at least once

These dependencies can be pre-built by invoking dearimgui-build.cmd $(Configuration).

Extending

It should be possible to support other libraries such as imguizmo and imnodes.

Take a look at how implot is generated and the shared code used by generators.

However, few things may prove to be challenging due to how CppSharp works.

When bindings are generated, there is a version history for easily diff'ing them.

Known issues

Generator can't write output file:

Occasionally, you may encounter a similiar exception while generating:

4>Unhandled exception. System.IO.IOException: The process cannot access the file 'C:\...\DearImGui\DearImGui.Generator\bin\Release\net6.0\imgui.cs' because it is being used by another process.

Something has outstanding handles on that file, try to generate again.

Tips

Building with dearimgui-build.cmd within Visual Studio Code is the best approach.

You can add an equivalent terminal profile to get the Developer Command Prompt:

"terminal.integrated.profiles.windows": {
    "Developer Command Prompt": {
        "path": [
            "${env:windir}\\System32\\cmd.exe"
        ],
        "args": [
            "/K",
            "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\Tools\\VsDevCmd.bat",
        ],
        "icon": "terminal-cmd"
    }
}

Credits

https://github.com/ocornut/imgui

https://github.com/epezent/implot

https://github.com/mono/CppSharp

https://github.com/opentk/opentk

https://github.com/dotnet/pinvoke

https://github.com/dotnet/roslyn

https://github.com/dotnet/sourcelink

https://fonts.google.com/specimen/Roboto

https://www.jetbrains.com/resharper/