No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-03 13:21:35 +01:00
examples Add Feature Vulkan Renderer 2026-02-06 21:32:39 +01:00
src Add Feature Vulkan Renderer 2026-02-06 21:32:39 +01:00
.gitignore Overhaul backend: fix UB, migrate to event API, upgrade deps 2026-02-06 20:34:38 +01:00
Cargo.toml Bump GLFW version 2026-11-03 13:21:35 +01:00
imgui.ini Add Feature Vulkan Renderer 2026-02-06 21:32:39 +01:00
LICENSE_APACHE License and Readme rework 2019-01-29 12:42:06 +01:00
LICENSE_MIT License and Readme rework 2019-01-29 12:42:06 +01:00
README.md update docs and versions of renderer 2026-02-06 22:03:11 +01:00

imgui-glfw-rs: GLFW Input handling for ImGui

crates.io Documentation on docs.rs Dependencies

GLFW input handling for imgui

Features

No features are enabled by default. Pick the renderer you need:

  • opengl — bundles the imgui-opengl-renderer-rs crate so a single ImguiGLFW value handles both input and rendering.
  • vulkan — bundles the imgui-vulkan-renderer-rs crate and re-exports it for Vulkan-based rendering.
# OpenGL
imgui-glfw-rs = { version = "0.13.1", features = ["opengl"] }

# Vulkan
imgui-glfw-rs = { version = "0.13.1", features = ["vulkan"] }

Without either feature, ImguiGLFW handles input only — call update_cursors() and your own renderer each frame instead of draw().

Prerequisites

You need a C compiler and CMake to build GLFW from source (handled automatically by the glfw-sys crate).

Debian / Ubuntu:

sudo apt install build-essential cmake libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgl-dev

For the Vulkan example, also install:

sudo apt install libvulkan-dev

Windows:

Install CMake and a C compiler (MSVC via Visual Studio or MinGW). For the Vulkan example, install the Vulkan SDK.

How to use

OpenGL

use imgui_glfw_rs::glfw;
use imgui_glfw_rs::imgui;
use imgui_glfw_rs::ImguiGLFW;

fn main() {
    // Initialize glfw with an OpenGL context and load GL functions.
    // { ... }

    let mut imgui_glfw = ImguiGLFW::new(&mut imgui, &mut window).unwrap();

    while !window.should_close() {
        let ui = imgui_glfw.frame(&mut window, &mut imgui);

        // Draw your ui.
        // { ... }

        imgui_glfw.draw(&mut imgui, &mut window);
        window.swap_buffers();

        glfw.poll_events();
        for (_, event) in glfw::flush_messages(&events) {
            imgui_glfw.handle_event(&mut imgui, &event);
        }
    }
}

Vulkan

use imgui_glfw_rs::glfw;
use imgui_glfw_rs::imgui;
use imgui_glfw_rs::imgui_vulkan_renderer_rs::{Renderer, RendererCreateInfo};
use imgui_glfw_rs::ImguiGLFW;

fn main() {
    // Initialize glfw with ClientApi(NoApi) and set up Vulkan
    // (instance, device, swapchain, render pass, etc.).
    // { ... }

    let mut imgui_glfw = ImguiGLFW::new(&mut imgui, &mut window);
    let mut renderer = Renderer::new(&mut imgui, &create_info).unwrap();

    while !window.should_close() {
        let ui = imgui_glfw.frame(&mut window, &mut imgui);

        // Draw your ui.
        // { ... }

        imgui_glfw.update_cursors(&imgui, &mut window);
        let draw_data = imgui.render();

        // Record command buffer, begin render pass, then:
        renderer.render(draw_data, command_buffer).unwrap();

        glfw.poll_events();
        for (_, event) in glfw::flush_messages(&events) {
            imgui_glfw.handle_event(&mut imgui, &event);
        }
    }
}

See examples/hello_opengl.rs and examples/hello_vulkan.rs for complete working examples.

Current implemented things

  • Mouse button press and release (event-based API)
  • Cursor position movement (event-based API)
  • Scroll movement (vertical and horizontal)
  • Char input
  • Key press and release
  • Modifier handling
  • Cursor icons (with change-detection optimization)
  • Clipboard copying/pasting
  • HiDPI / framebuffer scale support
  • Window focus tracking
  • Cursor enter/leave tracking
  • handle_event() returns whether imgui captured the event

Unimplemented things and known issues

  • Gamepad / joystick input

Compiling and running the examples

git clone https://github.com/K4ugummi/imgui-glfw-rs.git
cd imgui-glfw-rs
cargo run --example hello_opengl --features opengl

# Vulkan example (requires Vulkan SDK)
cargo run --example hello_vulkan --features vulkan

Contributing

  1. Make some changes
  2. Run rustfmt for code style conformance cargo fmt
  3. Open a pull request

Thanks to