Skip to content

CPlusPlus

Patrick Dawson edited this page Jul 13, 2024 · 10 revisions

Compatible with both C++ modules and GDExtensions.

You need to:

  • Add [path to your project]/addons/imgui-godot/include to your include path
  • Add your own copy of the Dear ImGui sources, using the exact same commit that imgui-godot was built with
  • Build everything with -DIMGUI_USER_CONFIG="imconfig-godot.h"

For GDExtension:

  • Call ImGui::Godot::SyncImGuiPtrs() in a _ready() method or similar, before calling any ImGui function. It only needs to be called once, but it's safe to do so multiple times.
  • It is also (as of v5.1.0) safe to call SyncImGuiPtrs() in your registered initializer function. Be sure that p_level == MODULE_INITIALIZATION_LEVEL_SCENE.

For modules:

  • Add the macro IMGUI_GODOT_MODULE_INIT() in exactly one of your source files. This exports a function that imgui-godot calls to synchronize the ImGui contexts.

Notes

In addition to functioning as an ImGui backend, this plugin is also responsible for:

  • Creating the ImGuiContext
  • Loading fonts
  • Calling NewFrame/EndFrame at the beginning and end of each process step

The context is created early (during MODULE_INITIALIZATION_LEVEL_SERVERS), but fonts are loaded after the scene tree is created. If you've configured custom fonts, they can be safely accessed in io.Fonts->Fonts in your node's _ready() method.

Clone this wiki locally