Skip to main content

Overview

The examples/ folder contains standalone, ready-to-build example applications for a variety of platforms and graphics APIs. These examples demonstrate how to integrate Dear ImGui with different backends and serve as starting points for your own projects.
Integration in a typical existing application takes fewer than 20 lines when using standard backends.

Getting Started

All examples use standard backends from the backends/ folder. Here’s the basic integration pattern:
// At initialization:
call ImGui::CreateContext()
call ImGui_ImplXXXX_Init() for each backend.

// At the beginning of your frame:
call ImGui_ImplXXXX_NewFrame() for each backend.
call ImGui::NewFrame()

// At the end of your frame:
call ImGui::Render()
call ImGui_ImplXXXX_RenderDrawData() for your Renderer backend.

// At shutdown:
call ImGui_ImplXXXX_Shutdown() for each backend.
call ImGui::DestroyContext()

Demo Window

Once Dear ImGui is running, run and refer to ImGui::ShowDemoWindow() in imgui_demo.cpp for usage of the end-user API. This is the best way to learn!
// In your render loop
ImGui::ShowDemoWindow();

Available Examples

Desktop - OpenGL

GLFW + OpenGL3

Platform: Windows, macOS, LinuxFiles: main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cppModern programmable pipeline with shader support. Supports Emscripten/WebGL compilation.Recommended for: Modern OpenGL applications

GLFW + OpenGL2

Platform: Windows, macOS, LinuxFiles: main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cppLegacy fixed pipeline.⚠️ Not recommended for modern GL or WebGL applications

SDL2 + OpenGL3

Platform: Windows, macOS, Linux, etc.Files: main.cpp + imgui_impl_sdl2.cpp + imgui_impl_opengl3.cppModern programmable pipeline. Supports Emscripten/WebGL.

SDL3 + OpenGL3

Platform: Windows, macOS, Linux, etc.Files: main.cpp + imgui_impl_sdl3.cpp + imgui_impl_opengl3.cppLatest SDL3 with modern OpenGL.

Desktop - DirectX (Windows)

Win32 + DirectX11

Platform: Windows onlyFiles: main.cpp + imgui_impl_win32.cpp + imgui_impl_dx11.cppDirectX 11 renderer with native Win32 window.

Win32 + DirectX12

Platform: Windows onlyFiles: main.cpp + imgui_impl_win32.cpp + imgui_impl_dx12.cppDirectX 12 renderer (long and tedious because: DirectX12).

SDL2 + DirectX11

Platform: Windows onlyFiles: main.cpp + imgui_impl_sdl2.cpp + imgui_impl_dx11.cppDemonstrates DirectX usage with SDL2.

Win32 + DirectX9

Platform: Windows onlyFiles: main.cpp + imgui_impl_win32.cpp + imgui_impl_dx9.cppLegacy DirectX 9 support.

Desktop - Vulkan

GLFW + Vulkan

Platform: Windows, macOS, LinuxFiles: main.cpp + imgui_impl_glfw.cpp + imgui_impl_vulkan.cppVulkan API example (quite long because: Vulkan). Uses helper functions from imgui_impl_vulkan.

SDL2 + Vulkan

Platform: Windows, macOS, LinuxFiles: main.cpp + imgui_impl_sdl2.cpp + imgui_impl_vulkan.cppSDL2 with Vulkan renderer.

Win32 + Vulkan

Platform: WindowsFiles: main.cpp + imgui_impl_win32.cpp + imgui_impl_vulkan.cppNative Win32 window with Vulkan.

SDL3 + Vulkan

Platform: Windows, macOS, LinuxFiles: main.cpp + imgui_impl_sdl3.cpp + imgui_impl_vulkan.cppLatest SDL3 with Vulkan renderer.

Desktop - Metal (Apple)

Apple Metal

Platform: macOS, iOSFiles: main.m + imgui_impl_osx.mm + imgui_impl_metal.mmBased on Xcode 9+ “cross-platform” game template.

GLFW + Metal

Platform: macOSFiles: main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mmGLFW with Metal renderer for macOS.

SDL2 + Metal

Platform: macOSFiles: main.mm + imgui_impl_sdl2.cpp + imgui_impl_metal.mmSDL2 with Metal renderer for macOS.

SDL3 + Metal

Platform: macOSFiles: main.cpp + imgui_impl_sdl3.cpp + imgui_impl_metal.mmLatest SDL3 with Metal renderer.

Desktop - WebGPU

GLFW + WebGPU

Platform: Emscripten (web), Dawn (native), WGPU (native)Files: main.cpp + imgui_impl_glfw.cpp + imgui_impl_wgpu.cppModern WebGPU API support.

SDL2 + WebGPU

Platform: Emscripten (web), Dawn (native), WGPU (native)Files: main.cpp + imgui_impl_sdl2.cpp + imgui_impl_wgpu.cppSDL2 with WebGPU support.

Desktop - Other

Platform: Linux/Windows (FreeGLUT), macOS (GLUT framework)Files: main.cpp + imgui_impl_glut.cpp + imgui_impl_opengl2.cpp
GLUT/FreeGLUT is largely obsolete software. Prefer using GLFW or SDL.
Platform: Cross-platformFiles: main.cpp + imgui_impl_allegro5.cppAllegro 5 game programming library.
Platform: AnyFiles: main.cpp + imgui_impl_null.cppHeadless example with no graphics output. Used for testing compilation. The null backend is intentionally minimal.

Mobile

Platform: AndroidFiles: main.cpp + imgui_impl_android.cpp + imgui_impl_opengl3.cppAndroid application with OpenGL ES support.

SDL Renderer

SDL2 + SDL_Renderer

Files: main.cpp + imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cppUses SDL’s built-in 2D renderer. Requires SDL 2.0.18+ (November 2021).

SDL3 + SDL_Renderer

Files: main.cpp + imgui_impl_sdl3.cpp + imgui_impl_sdlrenderer3.cppLatest SDL3 with built-in renderer.

SDL3 + SDL_GPU

Files: main.cpp + imgui_impl_sdl3.cpp + imgui_impl_sdlgpu3.cppSDL3 with new GPU API.

Building Examples

Most examples provide:
  • Makefiles for Linux/macOS
  • Batch files for Visual Studio 2008+
  • Solution files (.sln) for Visual Studio 2012+
  • Xcode projects for Apple platforms
You can also import imgui_impl_xxx.cpp/.h files directly into your codebase or compile them with command-line tools.

CMake Support

While official examples don’t use CMake, community CMake support is available:

Binary Downloads

Windows binaries for some examples are available at:

Integration Resources

  1. Read the Getting Started guide on the Wiki
  2. Read docs/BACKENDS.md or online at https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md
  3. Read PROGRAMMER GUIDE section in imgui.cpp
  4. Read the comments at the top of each backend file
  5. Study the example code that matches your target platform

Mouse Cursor Latency

Dear ImGui doesn’t introduce significant extra lag for most behaviors. At 60 FPS, your experience should be pleasant.
OS mouse cursors are typically rendered through hardware-accelerated paths, making them feel smoother than content rendered via regular graphics APIs. This disconnect may be noticeable to sensitive users.You can experiment with io.MouseDrawCursor = true to request Dear ImGui draw a cursor using the graphics API. However, rendering at 60 FPS will feel sluggish.Consider switching to a software cursor only during interactive drags.

Learning from Examples

Example Structure

Most examples follow this pattern:
int main(int, char**)
{
    // Setup window and graphics context
    // ...
    
    // Setup Dear ImGui context
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO();
    
    // Setup Dear ImGui style
    ImGui::StyleColorsDark();
    
    // Setup Platform/Renderer backends
    ImGui_ImplGlfw_InitForOpenGL(window, true);
    ImGui_ImplOpenGL3_Init(glsl_version);
    
    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        // Poll and handle events
        glfwPollEvents();
        
        // Start the Dear ImGui frame
        ImGui_ImplOpenGL3_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame();
        
        // Your UI code here
        ImGui::ShowDemoWindow();
        
        // Rendering
        ImGui::Render();
        int display_w, display_h;
        glfwGetFramebufferSize(window, &display_w, &display_h);
        glViewport(0, 0, display_w, display_h);
        glClear(GL_COLOR_BUFFER_BIT);
        ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
        
        glfwSwapBuffers(window);
    }
    
    // Cleanup
    ImGui_ImplOpenGL3_Shutdown();
    ImGui_ImplGlfw_Shutdown();
    ImGui::DestroyContext();
    
    return 0;
}

Tips for Choosing an Example

For Modern Applications

Choose OpenGL3, DirectX11/12, Vulkan, or Metal examples. These use modern programmable pipelines.

For Web Applications

Use GLFW + OpenGL3 or SDL2 + OpenGL3 examples with Emscripten compilation.

For Quick Prototyping

Start with GLFW + OpenGL3 or SDL2 + OpenGL3. They’re well-documented and widely supported.

For Game Engines

Choose the example matching your engine’s rendering API (DirectX, Vulkan, Metal, etc.).

Next Steps

  1. Choose an example matching your platform and graphics API
  2. Build and run the example to see Dear ImGui in action
  3. Study the code to understand the integration pattern
  4. Modify the example to experiment with Dear ImGui features
  5. Integrate into your project using the example as a template

See Also

Build docs developers (and LLMs) love