Should You Write a Custom Backend?
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:- Create and update textures
- Set up render state (blending, scissor, viewport)
- 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:Vertex Format
Dear ImGui uses this vertex format:Writing a Platform Backend
Required Functionality
A platform backend must:- Initialize and manage windows
- Process input events (mouse, keyboard, gamepad)
- Handle clipboard operations
- Update timing information
- 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 toImGuiKey enum:
Testing Your Backend
- Start with the demo window:
ImGui::ShowDemoWindow()exercises most features - Test input: Verify mouse, keyboard, and gamepad input work correctly
- Test rendering: Check that text, shapes, and images render correctly
- Test edge cases: Try resizing windows, HiDPI displays, minimizing
- 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
Next Steps
Examples
Study complete integration examples
GitHub Repository
Browse official backend implementations
Community Support
Ask questions and get help