Dear ImGui Deployment and Usage Guide
Prerequisites
- C++ Compiler: Visual Studio 2010 or newer, Xcode 9.0+, GCC 5.0+, or Clang 3.4+
- Graphics API Support: DirectX 11/12, OpenGL 3.0+, Vulkan 1.0+, or Metal (macOS/iOS)
- Build System: CMake 3.0+ or your preferred build system
- Backend Dependencies (choose one):
- GLFW 3.3+ (for GLFW backend)
- SDL2 (for SDL2 backend)
- Win32 API (for Windows native backend)
- Metal (for macOS/iOS native backend)
- etc.
Installation
-
Clone the repository:
git clone https://github.com/ocornut/imgui.git cd imgui -
Include in your project:
- Copy the
imgui/directory into your project source tree - Add the following core files to your build system:
imgui.himgui.cppimgui_demo.cppimgui_draw.cppimgui_tables.cppimgui_widgets.cpp
- Copy the
-
Select a backend (choose one):
- For GLFW:
imgui_impl_glfw.h,imgui_impl_glfw.cpp - For SDL2:
imgui_impl_sdl.h,imgui_impl_sdl.cpp - For DirectX11:
imgui_impl_dx11.h,imgui_impl_dx11.cpp - For OpenGL3:
imgui_impl_opengl3.h,imgui_impl_opengl3.cpp - For Vulkan:
imgui_impl_vulkan.h,imgui_impl_vulkan.cpp
- For GLFW:
Configuration
Backend Setup
For GLFW + OpenGL3 example:
// Initialize ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable keyboard controls
// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
// Setup Style
ImGui::StyleColorsDark();
Configuration Options
Set these in your code before creating the ImGui context:
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable keyboard navigation
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable gamepad controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable docking
io.ConfigWindowsResizeFromEdges = true; // Enable edge-based window resizing
Build & Run
Example: GLFW + OpenGL3
-
Create a main.cpp:
#include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #include <GLFW/glfw3.h> int main(int, char**) { // Setup window glfwInit(); GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL); glfwMakeContextCurrent(window); glfwSwapInterval(1); // Enable vsync // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; // Setup Dear ImGui style ImGui::StyleColorsDark(); // Setup Platform/Renderer bindings ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 130"); // Main loop while (!glfwWindowShouldClose(window)) { glfwPollEvents(); // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); // Show the ImGui demo window static bool show_demo_window = true; if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); // Rendering ImGui::Render(); int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(0.45f, 0.55f, 0.60f, 1.00f); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window); } // Cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); glfwDestroyWindow(window); glfwTerminate(); return 0; } -
Compile and run:
# Example using g++ with GLFW and OpenGL g++ -std=c++11 main.cpp -Iimgui -lglfw -lGL -ldl -o imgui_example ./imgui_example
CMake Integration
Create a CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(imgui_example)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
add_executable(imgui_example main.cpp)
target_include_directories(imgui_example PRIVATE imgui)
target_link_libraries(imgui_example glfw ${OPENGL_gl_LIBRARY})
Deployment
Dear ImGui is typically deployed as part of a larger application. Here are platform-specific considerations:
Desktop Applications
- Windows: Package with your application installer
- macOS: Bundle with your .app package
- Linux: Include in your distribution package
Web Applications (via WebAssembly)
- Use Emscripten to compile C++ to WebAssembly
- Include the ImGui backend for WebGL
- Deploy as static files on any web host (Vercel, Netlify, AWS S3, etc.)
Mobile Applications
- iOS: Include in Xcode project, use Metal backend
- Android: Use CMake with NDK, choose OpenGL/Vulkan backend
Troubleshooting
Common Issues
1. Black Screen / Nothing Renders
- Ensure your graphics context is properly initialized before calling ImGui functions
- Verify the backend initialization order: context → platform → renderer
- Check that you're calling
ImGui::Render()and the backend's render function
2. Compilation Errors
- Verify you're including the correct backend implementation files
- Ensure your compiler supports C++11 or newer
- Check that you've linked against the required graphics library (GLFW, SDL2, etc.)
3. Input Not Working
- Make sure you're calling the platform backend's
NewFrame()andRender()functions - Verify mouse/keyboard callbacks are properly forwarded to ImGui
- Check that
io.WantCaptureMouseandio.WantCaptureKeyboardare handled correctly
4. Performance Issues
- Use
ImGui::ShowMetricsWindow()to debug draw call counts - Enable
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewportsfor high-DPI displays - Consider using
ImGui::Begin()withImGuiWindowFlags_NoBackgroundfor overlay-style UIs
Debug Builds
Enable debug tools:
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;