#opengl #vulkan #windowing

glfw-passthrough

GLFW3 bindings and idiomatic wrapper for Rust with Passthrough patches

8 releases (5 breaking)

0.55.0 Feb 21, 2024
0.51.1 Feb 19, 2023
0.50.0 Feb 1, 2023
0.49.1 Jan 7, 2023
0.44.1 Aug 26, 2022

#212 in Graphics APIs

Download history 27/week @ 2024-07-19 26/week @ 2024-07-26 25/week @ 2024-08-02 20/week @ 2024-08-09 18/week @ 2024-08-16 20/week @ 2024-08-23 47/week @ 2024-08-30 42/week @ 2024-09-06 31/week @ 2024-09-13 55/week @ 2024-09-20 51/week @ 2024-09-27 43/week @ 2024-10-04 43/week @ 2024-10-11 28/week @ 2024-10-18 32/week @ 2024-10-25 54/week @ 2024-11-01

162 downloads per month
Used in 2 crates (via egui_window_glfw_passthro…)

Apache-2.0

180KB
3.5K SLoC

WARNING

README might be wrong because i left it as is for now. I eventually plan to abandon this library and revert back to original piston's glfw-rs, once glfw releases stable version 3.4 with the mouse passthrough patch.

glfw-rs

Crates.io Docs.rs Build Status

GLFW bindings and wrapper for The Rust Programming Language.

Example

use glfw_passthrough as 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 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-passthorugh in your project

Add this to your Cargo.toml:

[dependencies.glfw-passthrough]
version = "*"

On Windows

By default, glfw-rs-passthrough 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-passthrough]
git = "https://github.com/coderedart/glfw-rs-passthrough.git"
default-features = false

Dependencies

~1.1–4MB
~77K SLoC