imgui-glfw-rs (0.13.3)

Published 2026-11-03 13:23:12 +01:00 by elmisto in elmisto/imgui-glfw-rs

Installation

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add imgui-glfw-rs@0.13.3 --registry forgejo

About this package

ImGui input handling for GLFW

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

Dependencies

ID Version
ash ^0.38
gl ^0.14.0
glfw ^0.63.0
imgui ^0.12.0
imgui-opengl-renderer-rs ^0.12.3
imgui-vulkan-renderer-rs ^0.1.1
ash ^0.38
gl ^0.14.0

Keywords

imgui glfw opengl input gui
Details
Cargo
2026-11-03 13:23:12 +01:00
4
K4ugummi <stephan.schauerte@gmail.com>
MIT OR Apache-2.0
19 KiB
Assets (1)
Versions (2) View all
0.13.3 2026-11-03
0.13.2 2026-11-03