#windowing #window #framebuffer

minifb

Cross-platform window setup with optional bitmap rendering

44 releases (14 breaking)

✓ Uses Rust 2018 edition

0.16.0 Apr 5, 2020
0.15.3 Jan 21, 2020
0.15.1 Dec 27, 2019
0.13.0 Aug 30, 2019
0.5.0 Mar 4, 2016

#5 in Rendering

Download history 1026/week @ 2020-02-09 1310/week @ 2020-02-16 1232/week @ 2020-02-23 632/week @ 2020-03-01 1320/week @ 2020-03-08 1073/week @ 2020-03-15 1128/week @ 2020-03-22 850/week @ 2020-03-29 1290/week @ 2020-04-05 1116/week @ 2020-04-12 962/week @ 2020-04-19 1192/week @ 2020-04-26 898/week @ 2020-05-03 1008/week @ 2020-05-10 1252/week @ 2020-05-17 1310/week @ 2020-05-24

4,392 downloads per month
Used in 27 crates (25 directly)

MIT/Apache

285KB
7K SLoC

Ruby 6K SLoC // 0.1% comments Not Quite Perl 1K SLoC // 0.1% comments Coq 175 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. An example is the best way to show how it works:

Changelog

Usage

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

Example

extern crate minifb;

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.limit_update_rate(Some(std::time::Duration::from_micros(16600)));

    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). 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

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.4–1.8MB
~30K SLoC