GLFW3 bindings and idiomatic wrapper for Rust.

Related tags

Graphics glfw-rs
Overview

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

Comments
  • -lglfw Fails

    -lglfw Fails

    On OSX I got the following error: "ld: library not found for -lglfw". I still got the same error after making sure GLFW was correctly installed.

    After a while I figured that glfw uses "libglfw3.a" instead of "libglfw.a". After renaming "/usr/local/lib/libglfw3.a" to "libglfw.a" it worked.

    Not sure if anyone else got this error message, but just wanted to point this out.

    opened by leon-vv 31
  • Make Failing on Linux Mint

    Make Failing on Linux Mint

    mkdir -p lib
    rustc --out-dir=lib --link-args="-lglfw3 -lrt -lXrandr -lXi -lGL -lm -ldl -lXrender -ldrm -lXdamage -lX11-xcb -lxcb-glx -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp " -O src/lib/lib.rs
    error: linking with `cc` failed: exit code: 1
    note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'lib/libglfw-rs-c68009f4-0.1.so' 'lib/glfw-rs.o' 'lib/glfw-rs.metadata.o' '-Wl,--as-needed' '-Wl,-O1' '-L/home/sven/Desktop/opensource/glfw-rs/.rust' '-L/home/sven/Desktop/opensource/glfw-rs' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lstd-966edb7e-0.10-pre' '-ldl' '-lm' '-lpthread' '-shared' '-lmorestack' '-Wl,-rpath,$ORIGIN/../../../../../../usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lglfw3' '-lrt' '-lXrandr' '-lXi' '-lGL' '-lm' '-ldl' '-lXrender' '-ldrm' '-lXdamage' '-lX11-xcb' '-lxcb-glx' '-lXxf86vm' '-lXfixes' '-lXext' '-lX11' '-lpthread' '-lxcb' '-lXau' '-lXdmcp'
    note: /usr/bin/ld: /usr/local/lib/libglfw3.a(context.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libglfw3.a: could not read symbols: Bad value
    collect2: error: ld returned 1 exit status
    

    By running 'cat /proc/version' I get: Linux version 3.5.0-17-generic (buildd@allspice) (gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) ) #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012

    opened by bvssvni 27
  • Remove the channel from Window and place it into EventReceiver.

    Remove the channel from Window and place it into EventReceiver.

    This change is intended to help facilitate sharing of the window object with other tasks. This is needed if you have a render task that needs to call swap_buffers separately from the task that is handing input.

    Previously you could place the Window into a MutexArc and share it between tasks with some success. This type has been removed and replaced with Arc<Mutex<>>. The other problem came from the introduction of the Share trait, Receivers cannot be Shared which poisons the Window making it NoShare.

    This is a breaking change unfortunately.

    opened by ghost 23
  • undefined references

    undefined references

    I was trying to make one of the examples, and I got a few things like this: ../lib/libglfw3-9577b6c2f8956f17-0.1.so: undefined reference to `glfwGetScrollOffset'

    I am wondering if it didn't link to glfw3.h properly, or if it needs a pub in front of the definition now.

    question 
    opened by ccod 21
  • Use messaging instead of trait objects for event handling

    Use messaging instead of trait objects for event handling

    Instead of traits this uses ports and channels. Whenever glfw::poll_events(); is called, the events are sent to window-specific ports, along with the time stamp of when they were triggered. The events can be accessed using either the Window::events or Window::flush_events methods. For example:

    let window = glfw::Window::create(300, 300, "Hello this is window", glfw::Windowed).unwrap()
    
    // polling must be registered for the specific `WindowEvent` type
    window.set_key_polling(true);
    window.make_context_current();
    
    while !window.should_close() {
        glfw::poll_events();
        // `flush_events` returns an iterator that empties the messages received since
        // `events` or `flush_events` was last called.
        for (time, event) in window.flush_events() {
            println!("t = {}", time);
            match event {
                glfw::KeyEvent(glfw::KeyEscape, _, glfw::Press, _) => {
                    window.set_should_close(true)
                }
                _ => {}
            }
        }
    }
    
    opened by brendanzab 18
  • Enforce thread safety at the type level.

    Enforce thread safety at the type level.

    According to the GLFW docs, the following functions are thread-safe:

    • glfwGetVersion
    • glfwGetVersionString
    • glfwWindowShouldClose
    • glfwSetWindowShouldClose
    • glfwSetWindowUserPointer
    • glfwGetWindowUserPointer
    • glfwPostEmptyEvent
    • glfwGetTime
    • glfwMakeContextCurrent
    • glfwGetCurrentContext
    • glfwSwapBuffers
    • glfwSwapInterval
    • glfwExtensionSupported
    • glfwGetProcAddress

    and the following are thread-unsafe:

    • glfwInit
    • glfwTerminate
    • glfwSetErrorCallback
    • glfwGetMonitors
    • glfwGetPrimaryMonitor
    • glfwGetMonitorPos
    • glfwGetMonitorPhysicalSize
    • glfwGetMonitorName
    • glfwSetMonitorCallback
    • glfwGetVideoModes
    • glfwGetVideoMode
    • glfwSetGamma
    • glfwGetGammaRamp
    • glfwSetGammaRamp
    • glfwDefaultWindowHints
    • glfwWindowHint
    • glfwCreateWindow
    • glfwDestroyWindow
    • glfwSetWindowTitle
    • glfwGetWindowPos
    • glfwSetWindowPos
    • glfwGetWindowSize
    • glfwSetWindowSize
    • glfwGetFramebufferSize
    • glfwIconifyWindow
    • glfwRestoreWindow
    • glfwShowWindow
    • glfwHideWindow
    • glfwGetWindowMonitor
    • glfwGetWindowAttrib
    • glfwSetWindowPosCallback
    • glfwSetWindowSizeCallback
    • glfwSetWindowCloseCallback
    • glfwSetWindowRefreshCallback
    • glfwSetWindowFocusCallback
    • glfwSetWindowIconifyCallback
    • glfwSetFramebufferSizeCallback
    • glfwPollEvents
    • glfwWaitEvents
    • glfwGetInputMode
    • glfwSetInputMode
    • glfwGetKey
    • glfwGetMouseButton
    • glfwGetCursorPos
    • glfwSetCursorPos
    • glfwCreateCursor
    • glfwDestroyCursor
    • glfwSetCursor
    • glfwSetKeyCallback
    • glfwSetCharCallback
    • glfwSetMouseButtonCallback
    • glfwSetCursorPosCallback
    • glfwSetCursorEnterCallback
    • glfwSetScrollCallback
    • glfwSetDropCallback
    • glfwJoystickPresent
    • glfwGetJoystickAxes
    • glfwGetJoystickButtons
    • glfwGetJoystickName
    • glfwSetClipboardString
    • glfwGetClipboardString
    • glfwSetTime

    The rest of the functions are safe, as far as I know.

    A possible API:

    /// A type that lives on the main thread
    #[non_sendable]
    pub enum Glfw {}
    
    impl Glfw {
        pub fn init() -> Option<Glfw> { ... }
        pub fn poll_events() { ... }
        pub fn create_window(...) -> Option<Window> { ... }
    }
    

    Client code:

    let glfw = Glfw::init().unwrap();
    let window = glfw.create_window(...);
    
    opened by brendanzab 14
  • Build failure when compiling glfw-sys

    Build failure when compiling glfw-sys

    https://travis-ci.org/bjz/glfw-rs/builds/38563730#L243

     Compiling glfw-sys v3.0.4 (https://github.com/servo/glfw?ref=cargo-3.0.4#a3622cfd)
    Failed to run custom build command for `glfw-sys v3.0.4 (https://github.com/servo/glfw?ref=cargo-3.0.4#a3622cfd)`
    

    cc. @metajack

    opened by brendanzab 12
  • Fix compiler error about callback lifetime

    Fix compiler error about callback lifetime

    This fixes a compiler error I got after upgrading to the latest Rust version. The commit message contains details about the error.

    Please review this extra-carefully. I think I understand what I did there, but I'm not 100% sure :) I'm especially not sure, if this is the cleanest way to do this.

    Anyway, I've tested the examples, and they all still work, as far as I can tell.

    opened by hannobraun 12
  • Compiling a binary with glfw-rs rlib fails

    Compiling a binary with glfw-rs rlib fails

    I am using glfw-rs for 2 projects.

    The first is a library, and that compiles fine.

    However, when I try to use it in a binary, it gives me this error:

    note: lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_callbacks::hce5ef173e2a3e4a8zIaN::v0.1':
    glfw.rc:(.text+0x6791): undefined reference to `glfwGetWindowUserPointer'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Drop$Window::drop::h7dde909414fa68faqgaR::v0.1':
    glfw.rc:(.text+0x684d): undefined reference to `glfwDestroyWindow'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `init::hb88950b030c32452am::v0.1':
    glfw.rc:(.text+0x19d22): undefined reference to `glfwInit'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `terminate::h06a091ee8238c6adaH::v0.1':
    glfw.rc:(.text+0x19e12): undefined reference to `glfwTerminate'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_version::he6cde4145c45e0a6a9::v0.1':
    glfw.rc:(.text+0x1a2cb): undefined reference to `glfwGetVersion'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_version_string::h1c0968918b96f5fbaQ::v0.1':
    glfw.rc:(.text+0x1a332): undefined reference to `glfwGetVersionString'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_primary::h3853b6cbd7313615Y8aj::v0.1':
    glfw.rc:(.text+0x1a885): undefined reference to `glfwGetPrimaryMonitor'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_connected::h4be1565a895f30a4Y8av::v0.1':
    glfw.rc:(.text+0x1ac97): undefined reference to `glfwGetMonitors'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_pos::he59b4e2435e75c20Y8aC::v0.1':
    glfw.rc:(.text+0x1d0b1): undefined reference to `glfwGetMonitorPos'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_physical_size::h62c201859d501fd7Y8aD::v0.1':
    glfw.rc:(.text+0x1d141): undefined reference to `glfwGetMonitorPhysicalSize'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_name::h3aaa47ce9a49ff01Y8aE::v0.1':
    glfw.rc:(.text+0x1d1b1): undefined reference to `glfwGetMonitorName'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_video_modes::habc1eb616b4f6084Y8aF::v0.1':
    glfw.rc:(.text+0x1d222): undefined reference to `glfwGetVideoModes'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_video_mode::h37829ff8c22c4176Y8a5::v0.1':
    glfw.rc:(.text+0x1f3f2): undefined reference to `glfwGetVideoMode'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::set_gamma::hb72e6497bc957badY8af::v0.1':
    glfw.rc:(.text+0x1f795): undefined reference to `glfwSetGamma'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_gamma_ramp::he5620e904f03cc69Y8ag::v0.1':
    glfw.rc:(.text+0x1f7ea): undefined reference to `glfwGetGammaRamp'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::set_gamma_ramp::h0916bc26c5d52f68Y8aK::v0.1':
    glfw.rc:(.text+0x2029e): undefined reference to `glfwSetGammaRamp'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::default::h8b944d383993d970a9::v0.1':
    glfw.rc:(.text+0x20632): undefined reference to `glfwDefaultWindowHints'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::red_bits::h7734298ed8e426cdah::v0.1':
    glfw.rc:(.text+0x20691): undefined reference to `glfwWindowHint'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::green_bits::h7f16fb821c94c4f7ay::v0.1':
    glfw.rc:(.text+0x206f1): undefined reference to `glfwWindowHint'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::blue_bits::h9b7c12b1e849a2f3aP::v0.1':
    glfw.rc:(.text+0x20751): undefined reference to `glfwWindowHint'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::alpha_bits::hd09ef5f10535b0f1a6::v0.1':
    glfw.rc:(.text+0x207b1): undefined reference to `glfwWindowHint'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::depth_bits::h0e050a88d7071becan::v0.1':
    glfw.rc:(.text+0x20811): undefined reference to `glfwWindowHint'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o):glfw.rc:(.text+0x20871): more undefined references to `glfwWindowHint' follow
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::create_intern::h792ee9afba3b4e4bzIay::v0.1':
    glfw.rc:(.text+0x251e1): undefined reference to `glfwSetWindowUserPointer'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `__extensions__::create_intern::anon::expr_fn::ai':
    glfw.rc:(.text+0x3454b): undefined reference to `glfwCreateWindow'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::free_callbacks::h637276bd461f94fdzIag::v0.1':
    glfw.rc:(.text+0x35792): undefined reference to `glfwGetWindowUserPointer'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::should_close::h047252be1fe4a503zIak::v0.1':
    glfw.rc:(.text+0x358a1): undefined reference to `glfwWindowShouldClose'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_should_close::hadae698fe4194191zIal::v0.1':
    glfw.rc:(.text+0x35921): undefined reference to `glfwSetWindowShouldClose'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `__extensions__::set_title::anon::expr_fn::ar':
    glfw.rc:(.text+0x35f4b): undefined reference to `glfwSetWindowTitle'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_pos::h69c599f3faf9848dzIas::v0.1':
    glfw.rc:(.text+0x35fc1): undefined reference to `glfwGetWindowPos'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_pos::h78e8b5b34c0eb5c2zIat::v0.1':
    glfw.rc:(.text+0x36051): undefined reference to `glfwSetWindowPos'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_size::hd7b5c79ab4f4e6e4zIau::v0.1':
    glfw.rc:(.text+0x360c1): undefined reference to `glfwGetWindowSize'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_size::h6e6a6ebc34143f20zIav::v0.1':
    glfw.rc:(.text+0x36151): undefined reference to `glfwSetWindowSize'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_framebuffer_size::h5ee0e88cea57a5dezIaw::v0.1':
    glfw.rc:(.text+0x361c1): undefined reference to `glfwGetFramebufferSize'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::iconify::h9239e05fb0576a94zIax::v0.1':
    glfw.rc:(.text+0x36231): undefined reference to `glfwIconifyWindow'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::restore::h84ba1a72d7ea26e4zIay::v0.1':
    glfw.rc:(.text+0x36281): undefined reference to `glfwRestoreWindow'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::show::h205b5d6e76e80736zIaz::v0.1':
    glfw.rc:(.text+0x362d1): undefined reference to `glfwShowWindow'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::hide::h2056347b2fb7a27ezIaA::v0.1':
    glfw.rc:(.text+0x36321): undefined reference to `glfwHideWindow'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_window_mode::h18e6f73c5dabe00bzIaB::v0.1':
    glfw.rc:(.text+0x3637f): undefined reference to `glfwGetWindowMonitor'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::is_focused::h29eeb12ea5493e88zIaC::v0.1':
    glfw.rc:(.text+0x363f0): undefined reference to `glfwGetWindowAttrib'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::is_iconified::hc298a61aba6ab870zIaD::v0.1':
    glfw.rc:(.text+0x36470): undefined reference to `glfwGetWindowAttrib'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_client_api::he1249f6860386d7czIaE::v0.1':
    glfw.rc:(.text+0x364f0): undefined reference to `glfwGetWindowAttrib'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_context_version::h2ca46e692fb5857dzIaF::v0.1':
    glfw.rc:(.text+0x3655e): undefined reference to `glfwGetWindowAttrib'
    glfw.rc:(.text+0x3658d): undefined reference to `glfwGetWindowAttrib'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o):glfw.rc:(.text+0x365bd): more undefined references to `glfwGetWindowAttrib' follow
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_cursor_mode::h16cdc5d48d967c3ezIaN::v0.1':
    glfw.rc:(.text+0x36970): undefined reference to `glfwGetInputMode'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_cursor_mode::h55440baeefd04e0fzIaQ::v0.1':
    glfw.rc:(.text+0x36a36): undefined reference to `glfwSetInputMode'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::has_sticky_keys::h09b9a1262d5b4c15zIaR::v0.1':
    glfw.rc:(.text+0x36a90): undefined reference to `glfwGetInputMode'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_sticky_keys::h0ad44d21847c4abczIaS::v0.1':
    glfw.rc:(.text+0x36b20): undefined reference to `glfwSetInputMode'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::has_sticky_mouse_buttons::h2461e14db5144b47zIaT::v0.1':
    glfw.rc:(.text+0x36b80): undefined reference to `glfwGetInputMode'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_sticky_mouse_buttons::hd8408bc88a9fb7a8zIaU::v0.1':
    glfw.rc:(.text+0x36c10): undefined reference to `glfwSetInputMode'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_key::h344e6f53daaaeb6fzIaV::v0.1':
    glfw.rc:(.text+0x36c77): undefined reference to `glfwGetKey'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_mouse_button::h86aea726ecf8c2dfzIaW::v0.1':
    glfw.rc:(.text+0x36ce7): undefined reference to `glfwGetMouseButton'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_cursor_pos::h947f35b8095d91f3zIaX::v0.1':
    glfw.rc:(.text+0x36d7a): undefined reference to `glfwGetCursorPos'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_cursor_pos::ha23cc1df091e7831zIaY::v0.1':
    glfw.rc:(.text+0x36e09): undefined reference to `glfwSetCursorPos'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `__extensions__::set_clipboard_string::anon::expr_fn::a0':
    glfw.rc:(.text+0x36eeb): undefined reference to `glfwSetClipboardString'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_clipboard_string::ha224eb957a8495f0zIa1::v0.1':
    glfw.rc:(.text+0x36f41): undefined reference to `glfwGetClipboardString'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `make_context_current::hd639d7cec832c049ab::v0.1':
    glfw.rc:(.text+0x37013): undefined reference to `glfwMakeContextCurrent'
    glfw.rc:(.text+0x3702f): undefined reference to `glfwMakeContextCurrent'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::is_current_context::hf9cda9699d6bd0a8zIa4::v0.1':
    glfw.rc:(.text+0x370da): undefined reference to `glfwGetCurrentContext'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::swap_buffers::he54cab00b29677b0zIa5::v0.1':
    glfw.rc:(.text+0x37141): undefined reference to `glfwSwapBuffers'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_x11_window::h3d2e6e10df1aa548zIa6::v0.1':
    glfw.rc:(.text+0x37191): undefined reference to `glfwGetX11Window'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_glx_context::h0185add61ddaf201zIa7::v0.1':
    glfw.rc:(.text+0x371e1): undefined reference to `glfwGetGLXContext'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_x11_display::h88612354e98e4880aE::v0.1':
    glfw.rc:(.text+0x37222): undefined reference to `glfwGetX11Display'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `poll_events::h860eb0bc14878a18ae::v0.1':
    glfw.rc:(.text+0x37262): undefined reference to `glfwPollEvents'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `wait_events::h857bf203a08b782cam::v0.1':
    glfw.rc:(.text+0x372a2): undefined reference to `glfwWaitEvents'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::is_present::haf931ace8ec54046rxaJ::v0.1':
    glfw.rc:(.text+0x38c08): undefined reference to `glfwJoystickPresent'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::get_axes::h63185762ab9f3267rxaK::v0.1':
    glfw.rc:(.text+0x38c8a): undefined reference to `glfwGetJoystickAxes'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::get_buttons::h796fcd1261f65527rxaP::v0.1':
    glfw.rc:(.text+0x3a8aa): undefined reference to `glfwGetJoystickButtons'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::get_name::hd70983756f55c948rxaA::v0.1':
    glfw.rc:(.text+0x3bea8): undefined reference to `glfwGetJoystickName'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_time::h8b5ce6c98c399c9aaS::v0.1':
    glfw.rc:(.text+0x3bef2): undefined reference to `glfwGetTime'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `set_time::hcabab35afcda5ac7a3::v0.1':
    glfw.rc:(.text+0x3bf52): undefined reference to `glfwSetTime'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `set_swap_interval::h12e4a4b19770bec4aj::v0.1':
    glfw.rc:(.text+0x3bfa0): undefined reference to `glfwSwapInterval'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `extension_supported::anon::expr_fn::aF':
    glfw.rc:(.text+0x3c5c5): undefined reference to `glfwExtensionSupported'
    lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_proc_address::anon::expr_fn::aK':
    glfw.rc:(.text+0x3cbed): undefined reference to `glfwGetProcAddress'
    collect2: error: ld returned 1 exit status
    

    When I recompile glfw-rs as a dynamic library, and try again, it works fine.

    I suspect this is a linking problem, and you can't really fix it, but if that is the case, do you at least know of a workaround so I can use glfw-rs as a rlib?

    opened by HeroesGrave 12
  • Fixed WindowMode

    Fixed WindowMode

    • Made FullScreen wrap a borrowed Monitor.
    • Removed from_ptr
    • Changed ‘get_window_mode’ to take a closure.

    Code example to get full screen:

              let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
              let (window, events) = glfw.with_primary_monitor(|m| {
                  glfw.create_window(width, height, title, 
                      glfw::FullScreen(m.unwrap()))
                          .expect("Failed to create GLFW window.")
              });
    
    opened by bvssvni 11
  • Building against the latest master (for some time now) results in an ICE

    Building against the latest master (for some time now) results in an ICE

    Not sure where it's coming from, but something in the latest version of glfw-3 and rustc master results in the following error whenever I simply load the module.

    error: internal compiler error: parse_trait_store(): bad input '/'
    make: *** [all] Error 101
    

    Code being used:

    extern mod glfw;
    
    fn main() {
    
    }
    
    opened by jeaye 11
  • Using `glfwPostEmptyEvent` to wake `glfwWaitEvents` is not possible

    Using `glfwPostEmptyEvent` to wake `glfwWaitEvents` is not possible

    For creating an application which only refreshes when there is input, the use of Glfw::wait_events() is encouraged to avoid busy polling.

    This function will suspend the thread until there are events to process.

    The function Glfw::post_empty_event can be used to wake up the event processing thread in order to handle other events in the application, such as an internal refresh.

    wait_events requires a mutable reference to Glfw, and post_empty_event requires a reference to Glfw. As such, it is not possible to wake up a thread suspended by wait_events through the use of post_empty_event, as Glfw is both mutably borrowed, non-send, and non-sync.

    The docs mention that post_empty_event/glfwPostEmptyEvent is thread safe (which is the only way it could work`

    https://www.glfw.org/docs/3.3/input_guide.html#events

    opened by ten3roberts 0
  • Getting the current monitor?

    Getting the current monitor?

    Hello, I'm trying to implement fullscreen and windowed modes and I can't seem to figure out how to properly get the current monitor. This is the code I was hoping would work (but unfortunately didn't, as the ptr field of glfw::Monitor is private and can't be assigned to):

    let mut monitor = unsafe {
        let mut monitor = glfw::Monitor { ptr: glfw::ffi::glfwGetWindowMonitor(window.window_ptr()) };
        monitor
    };
    

    This is what the Window guide on the GLFW website says for C++:

    GLFWmonitor* monitor = glfwGetWindowMonitor(window);
    

    I'm new to Rust, so if something is obvious and I'm just missing it I apologize in advance.

    opened by shingle-bells 1
  • Version 0.46 tries to create a Wayland window by default

    Version 0.46 tries to create a Wayland window by default

    Since Wayland support was added, it seems like glfw will try to create a wayland window by default. This is because the "wayland" feature is active by default. Disabling it requires using default-features: false on glfw.

    Was this the intent? It seems like it might be easier to have it off by default, and activate by just using features = ["wayland"].

    opened by cloudhead 3
  • Update raw_window_handle 0.5.0 and implement HasRawWindowHandle + HasRawDisplayHandle

    Update raw_window_handle 0.5.0 and implement HasRawWindowHandle + HasRawDisplayHandle

    raw_window_handle has a new version which separates DisplayHandle and WindowHandle. It would be nice if glfw-rs supports these since packages like wgpu use it to communicate with the windowing-library in creating a surface.

    Made an attempt here https://github.com/EriKWDev/glfw-rs/commit/3b3fee7d08ab53563dbaeb1d9464af4699532e11 but it doesn't quite work. Examples compile and work but I'm getting errors if I try to use it with wgpu.

    opened by EriKWDev 1
  • Compilation Error on Wayland for version 0.46.0

    Compilation Error on Wayland for version 0.46.0

    I'm in the process of migrating egui_glfw_gl to latest version of glfw, but getting the following error when I change to 0.46.0 release on wayland (fedora).

    > cargo version -v
    cargo 1.64.0 (387270bc7 2022-09-16)
    release: 1.64.0
    commit-hash: 387270bc7f446d17869c7f208207c73231d6a252
    commit-date: 2022-09-16
    host: x86_64-unknown-linux-gnu
    libgit2: 1.4.2 (sys:0.14.2 vendored)
    libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
    os: Fedora 36.0.0 [64-bit]
    
    error: failed to run custom build command for `glfw-sys v4.0.0+3.3.5`
    
    Caused by:
      process didn't exit successfully: `/home/erik/Documents/GitHub/forks/egui_glfw_gl/target/debug/build/glfw-sys-ad1b1021c1502d5c/build-script-build` (exit status: 101)
      --- stdout
      CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
      CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
      HOST_CMAKE_TOOLCHAIN_FILE = None
      CMAKE_TOOLCHAIN_FILE = None
      CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
      CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
      HOST_CMAKE_GENERATOR = None
      CMAKE_GENERATOR = None
      CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
      CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
      HOST_CMAKE_PREFIX_PATH = None
      CMAKE_PREFIX_PATH = None
      CMAKE_x86_64-unknown-linux-gnu = None
      CMAKE_x86_64_unknown_linux_gnu = None
      HOST_CMAKE = None
      CMAKE = None
      running: "cmake" "/home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/glfw-sys-4.0.0+3.3.5/." "-DGLFW_BUILD_EXAMPLES=OFF" "-DGLFW_BUILD_TESTS=OFF" "-DGLFW_BUILD_DOCS=OFF" "-DCMAKE_INSTALL_LIBDIR=lib" "-DGLFW_BUILD_WAYLAND=ON" "-DCMAKE_INSTALL_PREFIX=/home/erik/Documents/GitHub/forks/egui_glfw_gl/target/debug/build/glfw-sys-3acccad1d5d4f989/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/lib64/ccache/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/lib64/ccache/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/lib64/ccache/cc" "-DCMAKE_BUILD_TYPE=Debug"
      -- Using Wayland for window creation
      -- Configuring incomplete, errors occurred!
      See also "/home/erik/Documents/GitHub/forks/egui_glfw_gl/target/debug/build/glfw-sys-3acccad1d5d4f989/out/build/CMakeFiles/CMakeOutput.log".
    
      --- stderr
      CMake Error at CMakeLists.txt:259 (find_package):
        Could not find a package configuration file provided by "ECM" with any of
        the following names:
    
          ECMConfig.cmake
          ecm-config.cmake
    
        Add the installation prefix of "ECM" to CMAKE_PREFIX_PATH or set "ECM_DIR"
        to a directory containing one of the above files.  If "ECM" provides a
        separate development package or SDK, be sure it has been installed.
    
    
      thread 'main' panicked at '
      command did not execute successfully, got: exit status: 1
    
      build script failed, must exit now', /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
      stack backtrace:
         0: rust_begin_unwind
                   at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5
         1: core::panicking::panic_fmt
                   at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14
         2: cmake::fail
                   at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
         3: cmake::run
                   at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:953:9
         4: cmake::Config::build
                   at /home/erik/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:780:13
         5: build_script_build::main
                   at ./build.rs:13:9
         6: core::ops::function::FnOnce::call_once
                   at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5
      note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    warning: build failed, waiting for other jobs to finish...
    

    Compilation works with version 0.45.0. Also, if I turn off defualt-features for version 0.46.0 and only enable glfw-sys feature, compilation still works fine.

    opened by EriKWDev 4
Owner
PistonDevelopers
The Piston game engine organization for maintenance and research
PistonDevelopers
Safe OpenGL wrapper for the Rust language.

glium Note to current and future Glium users: Glium is no longer actively developed by its original author. That said, PRs are still welcome and maint

null 3.1k Jan 1, 2023
Rust bindings to bgfx, a cross-platform, graphics API agnostic

Rust bindings to bgfx, a cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

Daniel Collin 65 Dec 24, 2022
A cool, fast maze generator and solver written in Rust

MazeCruncher Welcome to maze cruncher! Download Standalone Here Usage To get started, just run the standalone .exe in target/release or compile and ru

null 69 Sep 20, 2022
A high-performance SVG renderer, powered by Rust based resvg and napi-rs.

resvg-js resvg-js is a high-performance SVG renderer, powered by Rust based resvg and napi-rs. Fast, safe and zero dependencies! No need for node-gyp

一丝 744 Jan 7, 2023
A 2D vector graphics library optimized for GUIs, written in Rust and wgpu

RootVG A 2D vector graphics library optimized for GUIs, written in Rust and wgpu How it Works Unlike other 2D vector graphics libraries which have a s

Meadowlark 14 Jul 10, 2024
CLI for image processing with histograms, binary treshold and other functions

Image-Processing-CLI-in-Rust CLI for processing images in Rust. Some implementation is custom and for some functionality it uses 3rd party libraries.

Miki Graf 25 Jul 24, 2022
Sub-pixel precision light spot rendering library for astronomy and video tracking applications.

Planetarium Sub-pixel precision light spot rendering library for astronomy and video tracking applications. Example usage use planetarium::{Canvas, Sp

Sergey Kvachonok 5 Mar 27, 2022
A simple and elegant, pipewire graph editor

pw-viz A simple and elegant, pipewire graph editor This is still a WIP, node layouting is kinda jank at the moment. Installation A compiled binary is

null 180 Dec 27, 2022
A cargo subcommand for creating GraphViz DOT files and dependency graphs

cargo-graph Linux: A cargo subcommand for building GraphViz DOT files of dependency graphs. This subcommand was originally based off and inspired by t

Kevin K. 213 Nov 24, 2022
Szalinski: A Tool for Synthesizing Structured CAD Models with Equality Saturation and Inverse Transformations

Szalinski: A Tool for Synthesizing Structured CAD Models with Equality Saturation and Inverse Transformations

UW PLSE 24 Aug 15, 2022
Real-time 3D orientation visualization of a BNO055 IMU using Bissel and Bevy

orientation This is a demonstration of real-time visualization of the attitude of a BNO055 IMU across a wireless network to a Bevy app using the Bisse

chris m 4 Dec 10, 2022
Small, lightweight and fast library for rendering text with wgpu.

wgpu-text wgpu-text is a wrapper over glyph-brush for fast and easy text rendering in wgpu. This project was inspired by and is similar to wgpu_glyph,

Leon 20 Nov 30, 2022
Theorem relational dependencies automatic extraction and visualization as a graph for Lean4.

Lean Graph Interactive visualization of dependencies for any theorem/definitions in your Lean project. How to use In your browser: lean-graph.com Or r

Patrik Číhal 8 Jan 3, 2024
A toy ray tracer in Rust

tray_rust - A Toy Ray Tracer in Rust tray_rust is a toy physically based ray tracer built off of the techniques discussed in Physically Based Renderin

Will Usher 492 Dec 19, 2022
A low-overhead Vulkan-like GPU API for Rust.

Getting Started | Documentation | Blog gfx-rs gfx-rs is a low-level, cross-platform graphics and compute abstraction library in Rust. It consists of t

Rust Graphics Mages 5.2k Jan 8, 2023
A complete harfbuzz's shaping algorithm port to Rust

rustybuzz rustybuzz is a complete harfbuzz's shaping algorithm port to Rust. Matches harfbuzz v2.7.0 Why? Because you can add rustybuzz = "*" to your

Evgeniy Reizner 310 Dec 22, 2022
An OpenGL function pointer loader for Rust

gl-rs Overview This repository contains the necessary building blocks for OpenGL wrapper libraries. For more information on each crate, see their resp

Brendan Zabarauskas 621 Dec 17, 2022
A vector graphics renderer using OpenGL with a Rust & C API.

bufro A vector graphics renderer using OpenGL with a Rust & C API. A Rust example can be found in examples/quickstart.rs (using glutin). A C example c

Aspect 9 Dec 15, 2022
Graph data structure library for Rust.

petgraph Graph data structure library. Supports Rust 1.41 and later. Please read the API documentation here Crate feature flags: graphmap (default) en

null 2k Jan 9, 2023