Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
dear-imgui-sdl3
SDL3 platform backend (with optional OpenGL3 renderer) for the dear-imgui-rs
crate. This wraps the official Dear ImGui C++ backends:
imgui_impl_sdl3.cpp(platform layer)imgui_impl_opengl3.cpp(OpenGL3 renderer, via the shared sys shim)imgui_impl_sdlrenderer3.cpp(SDLRenderer (canvas) renderer, via the shared sys shim)
and exposes a small, Rust-friendly API that plugs into an existing
dear-imgui-rs::Context.
Typical use cases:
- Drive Dear ImGui input from an SDL3 window (keyboard/mouse/gamepad/IME).
- Render Dear ImGui via the official OpenGL3 backend.
- Use SDL3 only for the platform layer together with a Rust renderer
(e.g.
dear-imgui-glowordear-imgui-wgpu).
Notes
- This crate assumes a single Dear ImGui context and a single SDL3 event pump. The upstream SDL3 backend notes that multi-context usage is not well tested and may be dysfunctional.
- The upstream SDL3 backend source is compiled from the Dear ImGui tree packaged by
dear-imgui-sys, while this crate keeps the SDL3-specific build logic, Rust API, and SDL3 wrapper boundary. - When
opengl3-rendereris enabled, this crate uses the shared OpenGL3 backend shim exported bydear-imgui-sysinstead of compiling a second local OpenGL3 wrapper layer.
Features
opengl3-renderer: enables the shared official OpenGL3 renderer shim fromdear-imgui-sys.multi-viewport: enables multi-viewport helpers (requiresdear-imgui-rs/multi-viewport).
Platform-only usage (SDL3 + WGPU/Glow, no official OpenGL3 renderer):
= { = "0.11.0", = false }
Enable the official OpenGL3 renderer:
= { = "0.11.0", = ["opengl3-renderer"] }
Enable the official SDLRenderer3 renderer:
= { = "0.11.0", = ["sdlrenderer3-renderer"] }
Compatibility
| Item | Version |
|---|---|
| Crate | 0.11.0 |
| dear-imgui-rs | 0.11.0 |
| SDL3 crate | 0.17 |
| sdl3-sys | 0.6 |
See also: docs/COMPATIBILITY.md for the full workspace matrix.
Quick Start
Minimal SDL3 + OpenGL3 flow (single window):
use ;
use ;
use ;
APIs of interest (see src/lib.rs for full docs):
init_for_opengl(&mut Context, &Window, &GLContext, &str): initialize SDL3 platform + OpenGL3 renderer.init_for_opengl_default(&mut Context, &Window, &GLContext): initialize SDL3 platform + OpenGL3 renderer using the upstream default GLSL version.init_platform_for_opengl(&mut Context, &Window, &GLContext): initialize only the platform backend (for use with Rust OpenGL renderers).init_for_other(&mut Context, &Window): initialize only the platform backend (for use with WGPU or other APIs).init_for_vulkan(&mut Context, &Window)/init_for_metal(&mut Context, &Window)/init_for_d3d(&mut Context, &Window)/init_for_sdl_gpu(&mut Context, &Window): initialize the SDL3 platform backend for specific renderer families (useinit_for_vulkanfor Vulkan multi-viewport support).unsafe init_for_sdl_renderer(&mut Context, &Window, *mut SDL_Renderer): initialize SDL3 platform backend for SDL_Renderer-based renderers.shutdown_for_opengl(&mut Context)/shutdown(&mut Context): shut down the backends before destroying the ImGui context or window.new_frame(&mut Context): begin a frame for SDL3 + OpenGL3.sdl3_new_frame(&mut Context): begin a frame for SDL3 platform only.sdl3_poll_event_ll() -> Option<SDL_Event>andprocess_sys_event(&SDL_Event) -> bool: low-level event polling/processing helpers.render(&DrawData): render Dear ImGui draw data via the OpenGL3 backend.update_texture(&mut TextureData): advanced helper that delegates texture updates toImGui_ImplOpenGL3_UpdateTexture.create_device_objects()/destroy_device_objects(): advanced OpenGL3 helpers mirroring upstream device object management.
SDL3 & Build Requirements
The crate depends on:
sdl3andsdl3-sysfor SDL3 bindings.- A system SDL3 installation or a build-from-source configuration (OS-dependent).
Build behavior is aligned with Cargo.toml:
-
Linux / Windows
- The
sdl3dependency is configured withfeatures = ["build-from-source"]. - This means SDL3 is downloaded and built via CMake and does not require a pre-installed system SDL3 library.
- You still need a working C toolchain (compiler, linker, CMake).
- The
-
macOS
- The crate expects a system SDL3 install (for example via Homebrew):
brew install sdl3
- SDL3 headers are typically found under:
/opt/homebrew/include/SDL3/SDL.h(Apple Silicon)/usr/local/include/SDL3/SDL.h(Intel / custom setups)
- Linking parameters are handled by
sdl3-sys/sdl3; this crate only needs the headers to build the C++ backend sources.
- The crate expects a system SDL3 install (for example via Homebrew):
-
iOS
- The crate depends on the safe
sdl3crate on iOS targets as well, but it does not force one SDL3 acquisition strategy. - Treat this as an app-owned integration route:
- provide SDL3 headers yourself and set
SDL3_INCLUDE_DIRwhen discovery is not enough - make the final application dependency graph enable
sdl3/build-from-source - or use an app-owned
SDL3.xcframework/sdl3/link-frameworksetup
- provide SDL3 headers yourself and set
- The consuming app still owns:
- SDL3 framework packaging
- the host
mainentry point (SDL_RunAppor ansdl3-maincallback setup) - Xcode signing and bundle layout
- A repository-owned integration shape lives in
examples-ios/dear-imgui-ios-sdl3-smoke/. - That smoke template now includes a checked-in Xcode host stub which keeps
the packaging boundary explicit: it can either consume an app-owned
SDL3.framework/SDL3.xcframework, or buildSDL3.frameworkfrom the upstream SDL source distributed throughsdl3-src.
- The crate depends on the safe
-
Android
- The crate depends on the safe
sdl3crate on Android targets as well, but it does not forcesdl3/build-from-source. - Android application / NDK / activity packaging still belongs to the consuming application.
- Treat this as a supported integration direction, not a zero-config turn-key path.
- There are two supported ways to satisfy the SDL3 headers needed by this crate:
- provide SDL3 headers yourself and set
SDL3_INCLUDE_DIRwhen discovery is not enough - make the final application dependency graph enable
sdl3/build-from-source, sosdl3-sysexports headers viaDEP_SDL3_OUT_DIR
- provide SDL3 headers yourself and set
- The crate depends on the safe
Header Search Order and SDL3_INCLUDE_DIR
For cases where a system SDL3 is used, build.rs locates the headers in the
following order:
SDL3_INCLUDE_DIRenvironment variable (highest priority).pkg-config sdl3(if available).- A small set of common default paths (e.g.
/opt/homebrew/include,/usr/local/include,/opt/local/include).
1. Explicit SDL3_INCLUDE_DIR
Set this when SDL3 is installed in a non-standard location:
-
macOS (custom Homebrew prefix):
-
Linux (hand-built SDL3):
-
Windows (PowerShell, headers under
C:\libs\SDL3\include):$env:SDL3_INCLUDE_DIR="C:\libs\SDL3\include"
build.rs adds this directory to the C/C++ include path and expects to find
SDL3/SDL.h under it.
This is the preferred Android route when your application already owns the SDL3
integration (Gradle/NDK/Prefab/custom packaging) and just needs
dear-imgui-sdl3 to compile the official Dear ImGui SDL3 backend sources.
2. pkg-config sdl3
If SDL3_INCLUDE_DIR is not set, the build script tries:
On success, the reported include_paths are added to the compiler flags. This
is the preferred route for most Linux distributions and pkg-config-enabled
macOS setups.
3. Fallback paths
If both the environment variable and pkg-config checks fail, build.rs tries
a few common include roots (such as Homebrew / MacPorts locations) and looks
for SDL3/SDL.h there.
4. sdl3/build-from-source feature unification
If the final dependency graph enables sdl3/build-from-source, sdl3-sys
builds SDL3 from source and exports DEP_SDL3_OUT_DIR. This crate will then
reuse DEP_SDL3_OUT_DIR/include automatically.
This is especially useful when the application wants Cargo to drive the SDL3 build instead of relying on a system install.
When Headers Cannot Be Found
If the build script cannot locate SDL3 headers, it will panic with a message similar to:
dear-imgui-sdl3: could not find SDL3 headers.
Install SDL3 development files (e.g.brew install sdl3)
or set SDL3_INCLUDE_DIR to the SDL3 include path.
To fix this:
- Install SDL3 development packages and verify
pkg-config sdl3works, or - Set
SDL3_INCLUDE_DIRto the correct include root, or - Enable
sdl3/build-from-sourcein the final dependency graph sosdl3-sysexports SDL3 headers viaDEP_SDL3_OUT_DIR.
Android Integration Notes
Android integration in this crate should be understood as a low-friction path, not as a turn-key Android application template.
Recommended model:
- The consuming application owns SDL3 Android packaging, entry-point, and NDK toolchain decisions.
dear-imgui-sdl3owns the Dear ImGui SDL3 backend wrapper and can reuse whatever SDL3 headers the application chose to provide.- If the application wants Cargo to build SDL3 from source, it should add a
direct
sdl3dependency withfeatures = ["build-from-source"].
Example:
[]
= { = "0.11.0", = ["opengl3-renderer"] }
= { = "0.17", = ["build-from-source"] }
On Android, that route usually also requires the standard SDL/NDK build
toolchain environment expected by sdl3-sys, for example:
ANDROID_NDK/ANDROID_NDK_HOMEANDROID_ABI/CMAKE_ANDROID_ARCH_ABI(for examplearm64-v8a)CMAKE_TOOLCHAIN_FILECMAKE_GENERATOR=Ninja- a working
ninjaexecutable
In practice, this usually means the final application should drive the Android
build through a tool that already owns the ABI/toolchain contract
(cargo-ndk, Gradle+CMake, or an equivalent application build system) instead
of expecting dear-imgui-sdl3 alone to infer the full Android CMake setup.
Common Android Failure Modes
If you choose the sdl3/build-from-source route on Android, the most common
failures are application-toolchain issues rather than dear-imgui-sdl3
wrapper issues:
dear-imgui-sdl3: could not find SDL3 headers- Your final dependency graph did not actually enable
sdl3/build-from-source, or your application did not provideSDL3_INCLUDE_DIR.
- Your final dependency graph did not actually enable
CMake was unable to find a build program corresponding to "Ninja"sdl3-sysis trying to drive SDL3's Android CMake build, but your application environment did not makeninjaavailable to CMake.
- Android ABI mismatch during CMake compiler checks
- Example shape: CMake defaults to
armv7while Rust is buildingaarch64-linux-android. - In that case the application usually needs to set
ANDROID_ABI=arm64-v8aand/orCMAKE_ANDROID_ARCH_ABI=arm64-v8a, or use a tool such ascargo-ndk/ Gradle+CMake that manages those values.
- Example shape: CMake defaults to
The important boundary is:
dear-imgui-sdl3can reuse SDL3 once the application has made SDL3 headers and toolchain metadata availabledear-imgui-sdl3does not try to become the Android application build system
PowerShell Sketch For aarch64-linux-android
If your application owns the Android build directly from Cargo, the setup often looks roughly like this before you invoke your actual app build command:
$ndk = $env:ANDROID_NDK_HOME
$llvm = Join-Path $ndk 'toolchains/llvm/prebuilt/windows-x86_64/bin'
$env:ANDROID_NDK = $ndk
$env:ANDROID_ABI = 'arm64-v8a'
$env:CMAKE_ANDROID_ARCH_ABI = 'arm64-v8a'
$env:CMAKE_TOOLCHAIN_FILE = Join-Path $ndk 'build/cmake/android.toolchain.cmake'
$env:CMAKE_GENERATOR = 'Ninja'
$env:CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER = Join-Path $llvm 'aarch64-linux-android24-clang.cmd'
$env:CC_aarch64_linux_android = Join-Path $llvm 'aarch64-linux-android24-clang.cmd'
$env:CXX_aarch64_linux_android = Join-Path $llvm 'aarch64-linux-android24-clang++.cmd'
This is not something dear-imgui-sdl3 can infer safely on behalf of the
application. The final app build must own it.
If you do not want SDL3 at all, you can still build an Android backend manually
on top of dear-imgui-rs plus dear-imgui-sys::backend_shim::{android, opengl3}.
IME and Gamepad Configuration
The underlying SDL3 ImGui backend supports IME and gamepad input. This crate exposes a couple of small helpers to configure them.
IME UI
On platforms with heavy IME usage (e.g. Chinese/Japanese/Korean locales), it is recommended to enable the native IME UI before creating any SDL3 windows:
// Call this before creating SDL3 windows.
enable_native_ime_ui;
This is a convenience wrapper over SDL_HINT_IME_SHOW_UI, and failures are
treated as non-fatal.
Gamepad Mode
By default, the SDL3 backend opens the first available gamepad and feeds its state into Dear ImGui (the upstream default behavior).
You can switch to a mode where all detected gamepads are opened and merged:
use ;
// After init_for_opengl/init_for_other/init_platform_for_opengl:
set_gamepad_mode;
This is useful for local multiplayer setups or testing environments.
For advanced use cases, you can also opt into manual gamepad selection by
providing raw SDL_Gamepad* handles opened by your application:
// Safety: gamepads must be valid, opened SDL_Gamepad pointers.
unsafe
Examples
The workspace includes several examples that use this backend:
Multi-viewport status on SDL3:
-
SDL3 + OpenGL3: multi-viewport is provided by the upstream C++ backends and considered stable for desktop use.
-
SDL3 + Glow: multi-viewport is experimental but functional on native targets.
-
SDL3 + WGPU: multi-viewport is experimental on native targets; WebGPU/wasm is single-window to match upstream
imgui_impl_wgpu. -
SDL3 + OpenGL3, multi-viewport:
-
SDL3 + OpenGL3, multi-viewport (Glow renderer wrapper):
-
SDL3 + WGPU, single-window:
-
SDL3 + WGPU, multi-viewport (experimental, native only):
Note: WGPU multi-viewport support is experimental and only available on native targets
via dear-imgui-wgpu/multi-viewport-sdl3. WebGPU/wasm remains single-window to match
upstream imgui_impl_wgpu.