### GodotEnv Configuration for ImGui-Godot (JSON) Source: https://github.com/pkdawson/imgui-godot/blob/master/README.md Configuration example for using the GodotEnv package manager to install and manage the imgui-godot plugin. This JSON snippet specifies the repository URL, checkout branch, and subfolder for the addon. ```json { "addons": { "imgui-godot": { "url": "https://github.com/pkdawson/imgui-godot", "checkout": "6.x", "subfolder": "addons/imgui-godot" } } } ``` -------------------------------- ### Initialize and Process ImGui in Godot Tool Scripts (C#) Source: https://github.com/pkdawson/imgui-godot/wiki/In‐editor-GUI This snippet demonstrates how to initialize ImGuiGD for tool scripts in Godot using C#. It calls `ImGuiGD.ToolInit()` in `_Ready` and includes a placeholder for ImGui drawing logic within the `_Process` method, ensuring it only runs in the editor. ```csharp using Godot; using ImGuiGodot; using ImGuiNET; [Tool] public partial class AnotherTool : Node { private bool _showImGui = false; public override void _Ready() { if (Engine.IsEditorHint()) _showImShowGui = ImGuiGD.ToolInit(); } public override void _Process(double delta) { if (_showImGui) { // ImGui stuff } // do other stuff } } ``` -------------------------------- ### Link Libraries and Set Include Directories in CMake Source: https://github.com/pkdawson/imgui-godot/blob/master/doc/examples/GDExt/CMakeLists.txt This snippet configures the build by linking the 'gdexample' target against the 'godot-cpp' library and specifying necessary include directories. It also sets the output name for the target and defines the installation prefix. ```cmake target_link_libraries(gdexample PUBLIC godot-cpp) target_include_directories(gdexample PRIVATE src ${IMGUI_GODOT_INCLUDE} ${imgui_SOURCE_DIR} ${implot_SOURCE_DIR} ${imgui_markdown_SOURCE_DIR} ) set_property(TARGET gdexample PROPERTY OUTPUT_NAME "libgdexample.windows.template_$,debug,release>.x86_64") set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/project") install(TARGETS gdexample RUNTIME DESTINATION bin ) ``` -------------------------------- ### Connecting to ImGui Layout Signal in Godot C# Source: https://github.com/pkdawson/imgui-godot/blob/master/README.md An example of connecting to the `imgui_layout` signal provided by the ImGuiGD plugin in Godot. This is recommended for using ImGui, especially with process thread groups in Godot 4.1+. ```csharp ImGuiGD.Connect(OnImGuiLayout); ``` -------------------------------- ### Basic ImGui Usage in Godot C# Source: https://github.com/pkdawson/imgui-godot/blob/master/README.md Demonstrates how to integrate Dear ImGui into a Godot Node's _Process method using C#. It requires the ImGui.NET library and proper project setup, including enabling unsafe code and setting the target framework. ```csharp public partial class MyNode : Node { public override void _Process(double delta) { ImGui.Begin("ImGui on Godot 4"); ImGui.Text("hello world"); ImGui.End(); } } ``` -------------------------------- ### CMake Build Configuration for imgui-godot-native Source: https://github.com/pkdawson/imgui-godot/blob/master/gdext/CMakeLists.txt This CMake script configures the build for the imgui-godot-native library. It includes setting up vcpkg, fetching external dependencies like godot-cpp, defining compilation features and definitions, and managing target properties for different platforms. It also handles the installation of the library and its associated files. ```cmake cmake_minimum_required(VERSION 3.26) # using cmake for dev on Windows, scons for production builds # set up vcpkg if (WIN32) set(VCPKG_TARGET_TRIPLET x64-windows-static-md) endif() file(TO_CMAKE_PATH "$ENV{VCPKG_ROOT}" VCPKG_ROOT) set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") project(imgui-godot-native CXX) if (NOT TARGET godot-cpp) include(FetchContent) FetchContent_Declare( godot-cpp GIT_REPOSITORY https://github.com/godotengine/godot-cpp GIT_TAG 4.2 ) FetchContent_MakeAvailable(godot-cpp) endif() find_package(freetype CONFIG REQUIRED) #find_package(unofficial-lunasvg CONFIG REQUIRED) add_library(imgui-godot-native SHARED) target_compile_features(imgui-godot-native PRIVATE cxx_std_20) target_compile_definitions(imgui-godot-native PUBLIC IMGUI_USER_CONFIG="imconfig-godot.h" IMGUI_ENABLE_FREETYPE # IMGUI_ENABLE_FREETYPE_LUNASVG IGN_EXPORT # REAL_T_IS_DOUBLE ) # target_compile_definitions(godot-cpp PUBLIC # REAL_T_IS_DOUBLE # ) if (MSVC) target_compile_options(godot-cpp PRIVATE "/MP") target_compile_options(imgui-godot-native PRIVATE "/MP") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD ON) endif() add_subdirectory(src) target_sources(imgui-godot-native PRIVATE imgui/imgui.cpp imgui/imgui_demo.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/imgui.h imgui/misc/freetype/imgui_freetype.cpp imgui/misc/freetype/imgui_freetype.h include/imconfig-godot.h include/imgui-godot.h gen/imgui_bindings.gen.h gen/cimgui.cpp gen/cimgui.h ) target_link_libraries(imgui-godot-native PUBLIC godot-cpp freetype # unofficial::lunasvg::lunasvg ) target_include_directories(imgui-godot-native PRIVATE src imgui gen PUBLIC include) set_target_properties(imgui-godot-native PROPERTIES PUBLIC_HEADER "include/imconfig-godot.h;include/imgui-godot.h") if(WIN32) set_property(TARGET imgui-godot-native PROPERTY OUTPUT_NAME "libimgui-godot-native.windows.$,debug,release>.x86_64") elseif(APPLE) set_property(TARGET imgui-godot-native PROPERTY OUTPUT_NAME "imgui-godot-native.macos.$,debug,release>") set_target_properties(imgui-godot-native PROPERTIES SUFFIX "") endif() set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../addons/imgui-godot") if(WIN32) install(TARGETS imgui-godot-native RUNTIME DESTINATION bin PUBLIC_HEADER DESTINATION include ) elseif(APPLE) install(TARGETS imgui-godot-native DESTINATION bin/libimgui-godot-native.macos.$,debug,release>.framework PUBLIC_HEADER DESTINATION include ) endif() install(FILES "${CMAKE_SOURCE_DIR}/imgui-godot-native.gdextension" DESTINATION . ) ``` -------------------------------- ### Basic ImGui Usage in Godot GDScript Source: https://github.com/pkdawson/imgui-godot/blob/master/README.md Shows how to use Dear ImGui within a Godot Node's _Process method using GDScript. This requires the ImGuiGD plugin to be installed and enabled in the Godot project. ```gdscript extends Node func _process(delta): ImGui.Begin("My Window") ImGui.Text("hello from GDScript") ImGui.End() ``` -------------------------------- ### GDExtension Initialization for imgui-godot Source: https://github.com/pkdawson/imgui-godot/wiki/CPlusPlus For GDExtensions, call `ImGui::Godot::SyncImGuiPtrs()` once before using any ImGui functions. It can be called in `_ready()` or a registered initializer function with `MODULE_INITIALIZATION_LEVEL_SCENE`. ```gdscript func _ready(): ImGui.Godot.SyncImGuiPtrs() ``` -------------------------------- ### C++ Module Initialization for imgui-godot Source: https://github.com/pkdawson/imgui-godot/wiki/CPlusPlus For C++ modules, include the `IMGUI_GODOT_MODULE_INIT()` macro in exactly one source file to export a function that imgui-godot uses for synchronizing ImGui contexts. ```cpp #define IMGUI_GODOT_MODULE_INIT() // ... in exactly one source file ``` -------------------------------- ### Fetch and Configure External Libraries with CMake Source: https://github.com/pkdawson/imgui-godot/blob/master/doc/examples/GDExt/CMakeLists.txt This snippet demonstrates how to use CMake's FetchContent module to download and make available external libraries like godot-cpp, imgui, implot, and imgui_markdown. It specifies the Git repository and tag for each dependency. ```cmake include(FetchContent) FetchContent_Declare( godot-cpp GIT_REPOSITORY https://github.com/godotengine/godot-cpp GIT_TAG 4.2 ) FetchContent_MakeAvailable(godot-cpp) FetchContent_Declare( imgui GIT_REPOSITORY https://github.com/ocornut/imgui GIT_TAG v1.91.6-docking ) FetchContent_MakeAvailable(imgui) FetchContent_Declare( implot GIT_REPOSITORY https://github.com/epezent/implot GIT_TAG master ) FetchContent_MakeAvailable(implot) FetchContent_Declare( imgui_markdown GIT_REPOSITORY https://github.com/enkisoftware/imgui_markdown GIT_TAG main ) FetchContent_MakeAvailable(imgui_markdown) ``` -------------------------------- ### Define Library Target and Compile Options in CMake Source: https://github.com/pkdawson/imgui-godot/blob/master/doc/examples/GDExt/CMakeLists.txt This snippet defines a shared library target named 'gdexample'. It sets the C++ standard to C++20, defines user configurations for imgui, and applies multi-processor compilation options for MSVC. It also specifies the source files to be included in the library. ```cmake add_library(gdexample SHARED) target_compile_features(gdexample PRIVATE cxx_std_20) target_compile_definitions(gdexample PUBLIC IMGUI_USER_CONFIG="imconfig-godot.h" ) if (MSVC) target_compile_options(godot-cpp PRIVATE "/MP") target_compile_options(gdexample PRIVATE "/MP") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD ON) endif() target_sources(gdexample PRIVATE ${imgui_SOURCE_DIR}/imgui.cpp ${imgui_SOURCE_DIR}/imgui_demo.cpp ${imgui_SOURCE_DIR}/imgui_draw.cpp ${imgui_SOURCE_DIR}/imgui_tables.cpp ${imgui_SOURCE_DIR}/imgui_widgets.cpp ${imgui_SOURCE_DIR}/imgui.h ${implot_SOURCE_DIR}/implot.cpp ${implot_SOURCE_DIR}/implot_demo.cpp ${implot_SOURCE_DIR}/implot_items.cpp ${implot_SOURCE_DIR}/implot.h ${imgui_markdown_SOURCE_DIR}/imgui_markdown.h src/example.cpp src/example.h src/register_types.cpp src/register_types.h src/gdmarkdown.cpp src/gdmarkdown.h ) ``` -------------------------------- ### GDScript ImGui Basic Usage with Mutable Array Source: https://github.com/pkdawson/imgui-godot/wiki/GDScript Demonstrates basic ImGui window creation, displaying a draggable integer, and showing the integer's value in GDScript. It highlights the use of a one-element array to pass an integer by reference to ImGui.DragInt. ```gdscript var mynum := [42] func _process(_delta): ImGui.Begin("window name") ImGui.DragInt("my number", mynum) ImGui.Text("number = %d" % mynum[0]) ImGui.End() ``` -------------------------------- ### Conditionally Use ImGui in GDScript Source: https://github.com/pkdawson/imgui-godot/wiki/Export This GDScript snippet demonstrates how to conditionally enable ImGui functionality by checking for the 'ImGuiAPI' singleton. It's useful for preventing errors when ImGui is not available, such as during exports to unsupported platforms. Ensure the 'ImGuiAPI' singleton is present before attempting to use ImGui functions. ```gdscript if Engine.has_singleton("ImGuiAPI"): var ImGui: Object = Engine.get_singleton("ImGuiAPI") ImGui.Begin("hello") ImGui.End() ``` -------------------------------- ### Conditionally Use ImGui in C++ Source: https://github.com/pkdawson/imgui-godot/wiki/Export This C++ approach involves using defines within your build system (SCons/CMake) to conditionally compile ImGui code. Similar to C#, this allows you to control whether ImGui code is included in the final build. It's recommended not to include ImGui sources in your release build to optimize performance and reduce binary size. ```cpp // Example: Add a define in SCons/CMake // Example: Don't include imgui sources in release builds ``` -------------------------------- ### Conditionally Use ImGui in C# Source: https://github.com/pkdawson/imgui-godot/wiki/Export This C# code uses preprocessor directives to conditionally include ImGui calls. By defining a compilation symbol (e.g., 'IMGUI'), ImGui functions will only be compiled when this symbol is active. This is crucial for managing ImGui availability across different build configurations or export targets, such as enabling it in the editor or debug builds but excluding it from release builds. ```csharp #if IMGUI ImGui.Begin("hello"); ImGui.End(); #endif ``` -------------------------------- ### GDScript ImGui Incorrect Mutable Array Handling Source: https://github.com/pkdawson/imgui-godot/wiki/GDScript Illustrates an incorrect way to handle mutable parameters with ImGui.DragInt in GDScript. It shows that passing a literal array containing an integer directly to the function will not work as expected because the array itself is not stored and modified. ```gdscript # don't do this! ImGui.DragInt("an integer", [an_integer]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.