Skip to main content

Should You Write a Custom Backend?

Think twice before writing a custom backend! Standard backends are battle-tested and handle subtle edge cases that you’re likely to implement incorrectly. Consider using existing backends first.

When to Use Standard Backends

In most cases, you should use the standard backends:
  • Custom engine on Windows + DirectX11: Use imgui_impl_win32.cpp + imgui_impl_dx11.cpp
  • Cross-platform engine: Use multiple standard backends (e.g., GLFW on desktop, SDL on mobile)
  • High-level rendering system: Use standard platform backend + implement only a thin renderer wrapper

When Custom Backends Make Sense

  • Your platform isn’t supported (e.g., game consoles, embedded systems)
  • You need to integrate with a proprietary engine
  • You’re using a completely custom windowing/rendering system
Recommended approach: Get one standard backend working first to understand how Dear ImGui works, then adapt it to your needs.

Backend Architecture

Dear ImGui backends consist of two types:

Platform Backend

Handles OS interaction: windows, input events, clipboard, timing

Renderer Backend

Handles graphics: texture management, shader compilation, drawing triangles

Complexity Comparison

  • Writing a Renderer Backend: Relatively easy, ~200-500 lines of code
  • Writing a Platform Backend: More complex, higher chance of introducing bugs

Writing a Renderer Backend

Required Functionality

A renderer backend must:
  1. Create and update textures
  2. Set up render state (blending, scissor, viewport)
  3. Render indexed triangle lists with clipping

Step-by-Step Implementation

1

Backend Structure

Create the backend state structure:
2

Initialization

Set up the backend and advertise capabilities:
3

Texture Management

Implement texture creation and updates:
4

Render Setup

Configure render state for Dear ImGui:
5

Rendering

Implement the main rendering function:
6

Shutdown

Clean up resources:

Shader Requirements

Your vertex shader needs:
Your fragment shader needs:

Vertex Format

Dear ImGui uses this vertex format:

Writing a Platform Backend

Required Functionality

A platform backend must:
  1. Initialize and manage windows
  2. Process input events (mouse, keyboard, gamepad)
  3. Handle clipboard operations
  4. Update timing information
  5. Optionally: manage cursor shapes, IME, multi-viewports

Step-by-Step Implementation

1

Backend Structure

2

Initialization

3

Input Processing

4

Event Callbacks

Forward events to Dear ImGui:

Key Mapping

Map platform keys to ImGuiKey enum:

Testing Your Backend

  1. Start with the demo window: ImGui::ShowDemoWindow() exercises most features
  2. Test input: Verify mouse, keyboard, and gamepad input work correctly
  3. Test rendering: Check that text, shapes, and images render correctly
  4. Test edge cases: Try resizing windows, HiDPI displays, minimizing
  5. Test performance: Profile with large UIs (many windows, long lists)

Reference Implementations

Study these well-written backends:
  • Simple renderer: imgui_impl_opengl3.cpp (~500 lines)
  • Complex renderer: imgui_impl_vulkan.cpp (~2000 lines)
  • Simple platform: imgui_impl_glfw.cpp (~800 lines)
  • Complex platform: imgui_impl_win32.cpp (~1000 lines)

Common Pitfalls

Don’t forget:
  • Set ImGuiBackendFlags_RendererHasTextures and implement texture updates
  • Handle ImDrawCallback_ResetRenderState in custom callbacks
  • Support vertex offset (ImGuiBackendFlags_RendererHasVtxOffset) for large meshes
  • Map all keyboard keys to ImGuiKey enum
  • Update io.DeltaTime every frame
  • Handle window resize and DPI scaling

Next Steps

Examples

Study complete integration examples

GitHub Repository

Browse official backend implementations

Community Support

Ask questions and get help