#event-loop #opengl #wgpu #game #winit #graphics

gapp-winit

Abstract event loop library for winit-based applications with OpenGL and wgpu backends, integrating gapp traits for clean separation of input, update, render, and present

24 releases (12 breaking)

Uses new Rust 2024

0.13.2 Nov 18, 2026
0.13.0 Jul 31, 2026
0.11.0 Mar 10, 2026
0.9.0 Aug 10, 2025
0.1.0 Apr 12, 2021

#1120 in Game dev

Download history 45/week @ 2026-08-07 31/week @ 2026-08-14 8/week @ 2026-08-21 7/week @ 2026-08-28 6/week @ 2026-09-04 29/week @ 2026-09-11 10/week @ 2026-09-18 11/week @ 2026-09-25 6/week @ 2026-10-02 9/week @ 2026-10-09 9/week @ 2026-10-16 11/week @ 2026-10-23 12/week @ 2026-10-30 8/week @ 2026-11-06 34/week @ 2026-11-13 10/week @ 2026-11-20

64 downloads per month
Used in 3 crates

MIT/Apache

47KB
745 lines

gapp-winit

Crates.io Docs License

An abstract event loop library for winit-based applications with support for OpenGL/glutin and wgpu backends. Integrates seamlessly with gapp traits for clean separation of input, update, render, and present.

Supports native (Windows/Linux/macOS) and WASM. Fixed-timestep FPS cap, automatic resize handling, multi-window support.

Features

  • Multi-window: Manage multiple windows via Windows<R> collection, with per-window event routing.
  • Backend-agnostic: Switch between OpenGL and wgpu via Cargo features. The two are alternatives — each defines its own WindowData, so enabling both fails to compile with an explicit message. Select wgpu with default-features = false.
  • egui integration: EguiState (feature egui, pulls in wgpu) bundles the egui context, egui-winit input state, and egui-wgpu renderer for one window.
  • wgpu present helper: WindowData::present_wgpu covers the acquire/submit/present dance, including surface reconfiguration on Outdated.
  • Trait-based: Implement WindowInput, Present, Render (gapp), Update (gapp).
  • Cross-platform: Full WASM support (HTML canvas).
  • Performance: Fixed timestep, on-demand redraw, FPS sleep (native), optional render-on-demand loop (run_on_demand).
Feature OpenGL wgpu
Native ✅ ✅
WASM ✅ ✅
Default ✅ ❎️

Quickstart

For reference, have a look at the template program. It also can be used as a base for your program.

Traits Overview

  • WindowInput<C, R>: Handle all WindowEvents (post-resize/redraw) with WindowId and &mut Windows<R>. Call event_loop.exit() on close. Optional device_input hook for raw DeviceEvents (e.g. relative mouse motion), no-op by default.
  • Present<R>: Submit frame per window (e.g., queue.submit(), surface.swap_buffers()).
  • Render<R> / Update (from gapp): Standard render/update loop, called per window.
  • Windows<R>: Collection mapping WindowId → (WindowData, R). Insert/remove windows dynamically.

Resize is auto-handled per window.

FPS can be supplied to run.

run_on_demand is the battery-friendly alternative: the loop sleeps until input, a window event, a FrameWaker::wake from any thread, or Animation::is_animating returning true, and then updates and redraws at most fps times per second.

Dependencies

~5–49MB
~678K SLoC