#windowing #mouse-input #framebuffer #window

minifb

Cross-platform window setup with optional bitmap rendering

58 releases

0.27.0 May 20, 2024
0.25.0 Aug 2, 2023
0.24.0 Feb 18, 2023
0.23.0 Apr 19, 2022
0.5.0 Mar 4, 2016

#7 in Rendering

Download history 1933/week @ 2024-08-19 2630/week @ 2024-08-26 2290/week @ 2024-09-02 2259/week @ 2024-09-09 2249/week @ 2024-09-16 3011/week @ 2024-09-23 2481/week @ 2024-09-30 789/week @ 2024-10-07 1826/week @ 2024-10-14 1954/week @ 2024-10-21 2152/week @ 2024-10-28 1895/week @ 2024-11-04 1168/week @ 2024-11-11 1385/week @ 2024-11-18 2388/week @ 2024-11-25 1995/week @ 2024-12-02

7,032 downloads per month
Used in 86 crates (78 directly)

MIT/Apache

335KB
8K SLoC

Rust 6.5K SLoC // 0.0% comments Objective-C 1K SLoC // 0.2% comments C 205 SLoC // 0.0% comments

Build Status Crates.io Documentation

minifb is a cross platform library written in Rust and that makes it easy to setup a window and to (optional) display a 32-bit pixel buffer. It also makes it easy to get input from keyboard and mouse. Notice that minifb is primary designed for prototyping and may not include all the features found in full window handling libraries. An example is the best way to show how it works:

Changelog

Usage

# Cargo.toml
[dependencies]
minifb = "0.27"

Example

use minifb::{Key, Window, WindowOptions};

const WIDTH: usize = 640;
const HEIGHT: usize = 360;

fn main() {
    let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];

    let mut window = Window::new(
        "Test - ESC to exit",
        WIDTH,
        HEIGHT,
        WindowOptions::default(),
    )
    .unwrap_or_else(|e| {
        panic!("{}", e);
    });

    // Limit to max ~60 fps update rate
    window.set_target_fps(60);

    while window.is_open() && !window.is_key_down(Key::Escape) {
        for i in buffer.iter_mut() {
            *i = 0; // write something more funny here!
        }

        // We unwrap here as we want this code to exit if it fails. Real applications may want to handle this in a different way
        window
            .update_with_buffer(&buffer, WIDTH, HEIGHT)
            .unwrap();
    }
}

Status

Currently macOS, Linux and Windows (64-bit and 32-bit) are the current supported platforms. X11 (Linux/FreeBSD/etc) support has been tested on Ubuntu (x64). Linux Wayland support is also available. Bug report(s) for other OSes/CPUs are welcome! Notice: That after 0.13 Redox hasn't been updated and some work is required to get that working again. PR are welcome.

Build instructions

On Linux you may need to install these dependencies first:

sudo apt install libxkbcommon-dev libwayland-cursor0 libwayland-dev
cargo build
cargo run --example noise

This will run the noise example

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–12MB
~142K SLoC