#windowing #opengl #vulkan

glfw

GLFW3 bindings and idiomatic wrapper for Rust

46 releases (breaking)

0.33.0 Oct 8, 2019
0.31.0 Jul 31, 2019
0.26.1 Jan 22, 2019
0.25.1 Dec 19, 2018
0.0.6 Mar 7, 2015

#131 in Graphics APIs

Download history 604/week @ 2019-06-25 280/week @ 2019-07-02 214/week @ 2019-07-09 156/week @ 2019-07-16 197/week @ 2019-07-23 790/week @ 2019-07-30 377/week @ 2019-08-06 310/week @ 2019-08-13 679/week @ 2019-08-20 521/week @ 2019-08-27 473/week @ 2019-09-03 296/week @ 2019-09-10 608/week @ 2019-09-17 624/week @ 2019-09-24 391/week @ 2019-10-01

1,864 downloads per month
Used in 28 crates (19 directly)

Apache-2.0

160KB
2.5K SLoC

glfw-rs

Crates.io Docs.rs Build Status

GLFW bindings and wrapper for The Rust Programming Language.

Example

extern crate glfw;

use glfw::{Action, Context, Key};

fn main() {
    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();

    let (mut window, events) = glfw.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
        .expect("Failed to create GLFW window.");

    window.set_key_polling(true);
    window.make_current();

    while !window.should_close() {
        glfw.poll_events();
        for (_, event) in glfw::flush_messages(&events) {
            handle_window_event(&mut window, event);
        }
    }
}

fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
    match event {
        glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
            window.set_should_close(true)
        }
        _ => {}
    }
}

Using glfw-rs

Prerequisites

Make sure you have compiled and installed GLFW 3.x. You might be able to find it on your package manager, for example on OS X: brew install --static glfw3 (you may need to run brew tap homebrew/versions). If not you can download and build the library from the source supplied on the GLFW website. Note that if you compile GLFW with CMake on Linux, you will have to supply the -DCMAKE_C_FLAGS=-fPIC argument. You may install GLFW to your PATH, otherwise you will have to specify the directory containing the library binaries when you call make or make lib:

GLFW_LIB_DIR=path/to/glfw/lib/directory make

Including glfw-rs in your project

Add this to your Cargo.toml:

[dependencies.glfw]
git = "https://github.com/bjz/glfw-rs.git"

On Windows

By default, glfw-rs will try to compile the glfw library. If you want to link to your custom build of glfw or if the build doesn't work (which is probably the case on Windows), you can disable this:

[dependencies.glfw]
git = "https://github.com/bjz/glfw-rs.git"
default-features = false

Support

Contact bjz on irc.mozilla.org #rust and #rust-gamedev, or post an issue on Github.

glfw-rs in use

Dependencies

~1.2–1.8MB
~41K SLoC