diff --git a/backends/imgui_impl_null.cpp b/backends/imgui_impl_null.cpp new file mode 100644 index 000000000..eb99f5313 --- /dev/null +++ b/backends/imgui_impl_null.cpp @@ -0,0 +1,97 @@ +// dear imgui: Null Platform+Renderer Backends +// This is designed if you need to use a blind Dear Imgui context with no input and no output. + +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. +// Learn about Dear ImGui: +// - FAQ https://dearimgui.com/faq +// - Getting Started https://dearimgui.com/getting-started +// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). +// - Introduction, links and more at the top of imgui.cpp + +// CHANGELOG +// (minor and older changes stripped away, please see git history for details) +// 2025-11-17: Initial version. + +#include "imgui.h" +#ifndef IMGUI_DISABLE +#include "imgui_impl_null.h" + +bool ImGui_ImplNull_Init() +{ + ImGui_ImplNullPlatform_Init(); + ImGui_ImplNullRender_Init(); + return true; +} + +void ImGui_ImplNull_Shutdown() +{ + ImGui_ImplNullRender_Shutdown(); + ImGui_ImplNullPlatform_Shutdown(); +} + +void ImGui_ImplNull_NewFrame() +{ + ImGui_ImplNullPlatform_NewFrame(); + ImGui_ImplNullRender_NewFrame(); +} + +bool ImGui_ImplNullPlatform_Init() +{ + ImGuiIO& io = ImGui::GetIO(); + io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; + return true; +} + +void ImGui_ImplNullPlatform_Shutdown() +{ + ImGuiIO& io = ImGui::GetIO(); + io.BackendFlags &= ~ImGuiBackendFlags_HasMouseCursors; +} + +void ImGui_ImplNullPlatform_NewFrame() +{ + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize = ImVec2(1920, 1080); + io.DeltaTime = 1.0f / 60.0f; +} + +bool ImGui_ImplNullRender_Init() +{ + ImGuiIO& io = ImGui::GetIO(); + io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; + io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; + return true; +} + +void ImGui_ImplNullRender_Shutdown() +{ + ImGuiIO& io = ImGui::GetIO(); + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasTextures; +} + +void ImGui_ImplNullRender_NewFrame() +{ +} + +void ImGui_ImplNullRender_UpdateTexture(ImTextureData* tex) +{ + if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantDestroy) + tex->SetStatus(ImTextureStatus_OK); + if (tex->Status == ImTextureStatus_WantDestroy) + { + tex->SetTexID(ImTextureID_Invalid); + tex->SetStatus(ImTextureStatus_Destroyed); + } +} + +void ImGui_ImplNullRender_RenderDrawData(ImDrawData* draw_data) +{ + if (draw_data->Textures != nullptr) + for (ImTextureData* tex : *draw_data->Textures) + if (tex->Status != ImTextureStatus_OK) + ImGui_ImplNullRender_UpdateTexture(tex); +} + +#endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_null.h b/backends/imgui_impl_null.h new file mode 100644 index 000000000..b5cfb5a2c --- /dev/null +++ b/backends/imgui_impl_null.h @@ -0,0 +1,34 @@ +// dear imgui: Null Platform+Renderer Backends +// This is designed if you need to use a blind Dear Imgui context with no input and no output. + +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. +// Learn about Dear ImGui: +// - FAQ https://dearimgui.com/faq +// - Getting Started https://dearimgui.com/getting-started +// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). +// - Introduction, links and more at the top of imgui.cpp + +#pragma once +#include "imgui.h" // IMGUI_IMPL_API +#ifndef IMGUI_DISABLE + +// Follow "Getting Started" link and check examples/ folder to learn about using backends! + +// Null = NullPlatform + NullRender +IMGUI_IMPL_API bool ImGui_ImplNull_Init(); +IMGUI_IMPL_API void ImGui_ImplNull_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplNull_NewFrame(); + +// Null platform only (single screen, fixed timestep, no inputs) +IMGUI_IMPL_API bool ImGui_ImplNullPlatform_Init(); +IMGUI_IMPL_API void ImGui_ImplNullPlatform_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplNullPlatform_NewFrame(); + +// Null renderer only (no output) +IMGUI_IMPL_API bool ImGui_ImplNullRender_Init(); +IMGUI_IMPL_API void ImGui_ImplNullRender_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplNullRender_NewFrame(); +IMGUI_IMPL_API void ImGui_ImplNullRender_RenderDrawData(ImDrawData* draw_data); + +#endif // #ifndef IMGUI_DISABLE diff --git a/docs/BACKENDS.md b/docs/BACKENDS.md index 629f8d83f..62acb1e21 100644 --- a/docs/BACKENDS.md +++ b/docs/BACKENDS.md @@ -100,6 +100,7 @@ List of Renderer Backends: List of high-level Frameworks Backends (combining Platform + Renderer): imgui_impl_allegro5.cpp + imgui_impl_null.cpp Emscripten is also supported! The SDL2+GL, SDL3+GL, GLFW+GL and GLFW+WebGPU examples are all ready to build and run with Emscripten. diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7d65a172d..e0bf08e69 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -121,6 +121,8 @@ Other Changes: - Metrics: fixed table and columns rect highlight from display when debug/metrics window is not in the same viewport as the table. - Backends: + - Null: added imgui_impl_null platform/renderer backend. + This is designed if you need to run e.g. context with no input or no ouput. - GLFW: fixed building on Linux platforms where Wayland headers are not available. (#9024, #8969, #8921, #8920) [@jagot] - GLFW: lower minimum requirement from GLFW 3.1 to GLFW 3.0. Though diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index 45ad97309..676d745bc 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -109,9 +109,11 @@ Note that GLUT/FreeGLUT is largely obsolete software, prefer using GLFW or SDL. [example_null/](https://github.com/ocornut/imgui/blob/master/examples/example_null/)
Null example, compile and link imgui, create context, run headless with no inputs and no graphics output.
-= main.cpp
+= main.cpp + imgui_impl_null.cpp
This is used to quickly test compilation of core imgui files in as many setups as possible. Because this application doesn't create a window nor a graphic context, there's no graphics output. +Please note that imgui_impl_null itself is a rather empty backend. We provide it for consistency but +it is similarly easy to create a skeleton application without the null backend. [example_sdl2_directx11/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_directx11/)
SDL2 + DirectX11 example, Windows only.
diff --git a/examples/README.txt b/examples/README.txt index 6db2f3c48..1a711e7b8 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,9 +1,12 @@ -See BACKENDS and EXAMPLES files in the docs/ folder, or on the web at: https://github.com/ocornut/imgui/tree/master/docs +New to Dear ImGui? +- Check out the Getting Started guide: https://github.com/ocornut/imgui/wiki/Getting-Started +- About Backends: docs/BACKENDS.md file, or on the web: https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md +- About Examples: docs/EXAMPLES.md file, or on the web: https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md Backends = Helper code to facilitate integration with platforms/graphics api (used by Examples + should be used by your app). Examples = Standalone applications showcasing integration with platforms/graphics api. -Some Examples have extra README files in their respective directory, please check them too! +A few Examples have extra README files in their respective directory, please check them too! Once Dear ImGui is running (in either examples or your own application/game/engine), run and refer to ImGui::ShowDemoWindow() in imgui_demo.cpp for the end-user API. diff --git a/examples/example_null/build_win32.bat b/examples/example_null/build_win32.bat index be81d8093..3a07d8f8d 100644 --- a/examples/example_null/build_win32.bat +++ b/examples/example_null/build_win32.bat @@ -1,3 +1,3 @@ @REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. mkdir Debug -cl /nologo /Zi /MD /utf-8 /I ..\.. %* *.cpp ..\..\*.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib imm32.lib +cl /nologo /Zi /MD /utf-8 /I ..\.. %* *.cpp ..\..\*.cpp ..\..\backends\imgui_impl_null.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib imm32.lib diff --git a/examples/example_null/example_null.vcxproj b/examples/example_null/example_null.vcxproj new file mode 100644 index 000000000..7d0d59279 --- /dev/null +++ b/examples/example_null/example_null.vcxproj @@ -0,0 +1,173 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D} + example_win32_directx11 + + + + Application + true + Unicode + v140 + + + Application + true + Unicode + v140 + + + Application + false + true + Unicode + v140 + + + Application + false + true + Unicode + v140 + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + + Level4 + Disabled + ..\..;..\..\backends;%(AdditionalIncludeDirectories); + /utf-8 %(AdditionalOptions) + + + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + Disabled + ..\..;..\..\backends;%(AdditionalIncludeDirectories); + /utf-8 %(AdditionalOptions) + + + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;..\..\backends;%(AdditionalIncludeDirectories); + false + /utf-8 %(AdditionalOptions) + + + true + true + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;..\..\backends;%(AdditionalIncludeDirectories); + false + /utf-8 %(AdditionalOptions) + + + true + true + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + Console + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/example_null/example_null.vcxproj.filters b/examples/example_null/example_null.vcxproj.filters new file mode 100644 index 000000000..f5dd02f2d --- /dev/null +++ b/examples/example_null/example_null.vcxproj.filters @@ -0,0 +1,57 @@ + + + + + {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6} + + + {08e36723-ce4f-4cff-9662-c40801cf1acf} + + + + + imgui + + + imgui + + + imgui + + + sources + + + + + imgui + + + sources + + + imgui + + + imgui + + + imgui + + + imgui + + + sources + + + + + + imgui + + + imgui + + + diff --git a/examples/example_null/main.cpp b/examples/example_null/main.cpp index 460f33cab..5e94a6fb6 100644 --- a/examples/example_null/main.cpp +++ b/examples/example_null/main.cpp @@ -3,24 +3,23 @@ // This is useful to test building, but you cannot interact with anything here! #include "imgui.h" #include +#include "imgui_impl_null.h" int main(int, char**) { IMGUI_CHECKVERSION(); + ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); - // Build atlas - //unsigned char* tex_pixels = nullptr; - //int tex_w, tex_h; - //io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h); - io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; + ImGui_ImplNullPlatform_Init(); + ImGui_ImplNullRender_Init(); for (int n = 0; n < 20; n++) { printf("NewFrame() %d\n", n); - io.DisplaySize = ImVec2(1920, 1080); - io.DeltaTime = 1.0f / 60.0f; + ImGui_ImplNullPlatform_NewFrame(); + ImGui_ImplNullRender_NewFrame(); ImGui::NewFrame(); static float f = 0.0f; @@ -33,6 +32,8 @@ int main(int, char**) } printf("DestroyContext()\n"); + ImGui_ImplNullRender_Shutdown(); + ImGui_ImplNullPlatform_Shutdown(); ImGui::DestroyContext(); return 0; } diff --git a/examples/imgui_examples.sln b/examples/imgui_examples.sln index 8ad1a2566..96087aeac 100644 --- a/examples/imgui_examples.sln +++ b/examples/imgui_examples.sln @@ -41,6 +41,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl3_sdlgpu3", "exa EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl3_directx11", "example_sdl3_directx11\example_sdl3_directx11.vcxproj", "{009DAC16-1A9C-47BE-9770-A30A046E8090}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_null", "example_null\example_null.vcxproj", "{1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -201,6 +203,14 @@ Global {009DAC16-1A9C-47BE-9770-A30A046E8090}.Release|Win32.Build.0 = Release|Win32 {009DAC16-1A9C-47BE-9770-A30A046E8090}.Release|x64.ActiveCfg = Release|x64 {009DAC16-1A9C-47BE-9770-A30A046E8090}.Release|x64.Build.0 = Release|x64 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Debug|Win32.ActiveCfg = Debug|Win32 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Debug|Win32.Build.0 = Debug|Win32 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Debug|x64.ActiveCfg = Debug|x64 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Debug|x64.Build.0 = Debug|x64 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Release|Win32.ActiveCfg = Release|Win32 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Release|Win32.Build.0 = Release|Win32 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Release|x64.ActiveCfg = Release|x64 + {1A0BF63C-18EF-4BAE-A8DA-055481B11F5D}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/imgui.h b/imgui.h index a52ec5764..e5e4dda91 100644 --- a/imgui.h +++ b/imgui.h @@ -29,7 +29,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') #define IMGUI_VERSION "1.92.5 WIP" -#define IMGUI_VERSION_NUM 19245 +#define IMGUI_VERSION_NUM 19246 #define IMGUI_HAS_TABLE // Added BeginTable() - from IMGUI_VERSION_NUM >= 18000 #define IMGUI_HAS_TEXTURES // Added ImGuiBackendFlags_RendererHasTextures - from IMGUI_VERSION_NUM >= 19198