#opengl #vulkan #窗口管理

glfw-passthrough

GLFW3的Rust绑定和具有Passthrough补丁的惯用包装

8个版本 (5个重大变更)

0.55.0 2024年2月21日
0.51.1 2023年2月19日
0.50.0 2023年2月1日
0.49.1 2023年1月7日
0.44.1 2022年8月26日

#139 in 图形API

Download history 14/week @ 2024-04-07 25/week @ 2024-04-14 48/week @ 2024-04-21 35/week @ 2024-04-28 30/week @ 2024-05-05 23/week @ 2024-05-12 44/week @ 2024-05-19 27/week @ 2024-05-26 45/week @ 2024-06-02 25/week @ 2024-06-09 28/week @ 2024-06-16 24/week @ 2024-06-23 5/week @ 2024-06-30 13/week @ 2024-07-07 17/week @ 2024-07-14 26/week @ 2024-07-21

63 每月下载量
2 个Crates中使用(通过 egui_window_glfw_passthrough

Apache-2.0

180KB
3.5K SLoC

警告

README可能不正确,因为我目前保持原样。我最终计划放弃这个库,并恢复到原始的piston的 glfw-rs,一旦glfw发布带有鼠标Passthrough补丁的稳定版本 3.4

glfw-rs

Crates.io Docs.rs Build Status

GLFW绑定和Rust编程语言的包装器。

示例

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)
        }
        _ => {}
    }
}

使用 glfw-rs

先决条件

确保您已编译并安装了GLFW 3.x。您可能可以在包管理器中找到它,例如在OS X上:brew install glfw3(您可能需要运行 brew tap homebrew/versions)。如果没有,您可以下载并从GLFW网站提供的源代码构建库。注意,如果您在Linux上使用CMake编译GLFW,您将需要提供 -DCMAKE_C_FLAGS=-fPIC 参数。您可以安装GLFW到您的 PATH,否则您在调用 makemake lib 时必须指定包含库二进制文件的目录。

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

将 glfw-rs-passthorugh 包含到您的项目中

将以下内容添加到您的 Cargo.toml

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

在Windows上

默认情况下,glfw-rs-passthrough 将尝试编译 glfw 库。如果您想链接到您自定义构建的 glfw 或如果构建不成功(在Windows上可能是这种情况),您可以禁用此功能

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

依赖关系

~1.1–3.5MB
~73K SLoC