- Notifications
You must be signed in to change notification settings - Fork126
GLFW3 bindings and idiomatic wrapper for Rust.
License
PistonDevelopers/glfw-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
GLFW bindings and wrapper for The Rust Programming Language.
externcrate glfw;use glfw::{Action,Context,Key};fnmain(){letmut 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);}}}fnhandle_window_event(window:&mut glfw::Window,event: glfw::WindowEvent){match event{ glfw::WindowEvent::Key(Key::Escape, _,Action::Press, _) =>{ window.set_should_close(true)} _ =>{}}}
Make sure you havecompiled 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 runbrew tap homebrew/versions
).If not you can download and build the libraryfrom the source supplied on theGLFW website. Note that if you compile GLFW with CMake on Linux, you will haveto supply the-DCMAKE_C_FLAGS=-fPIC
argument. You may install GLFW to yourPATH
, otherwise you will have to specify the directory containing the librarybinaries when you callmake
ormake lib
:
GLFW_LIB_DIR=path/to/glfw/lib/directory make
Add this to yourCargo.toml
:
[dependencies.glfw]version ="*"
By default,glfw-rs
will try to compile theglfw
library. If you want to link to your custombuild ofglfw
or if the build doesn't work (which is probably the case on Windows), you candisable this:
[dependencies.glfw]version ="*"default-features =false
By default,glfw-rs
uses raw-window-handle at v0.6.0. If your project is depending onglfw-rs
with raw-window-handle v0.5.0, then use this line in your Cargo.toml:
glfw = { version = 0.56.0 , default-features = false, features = ["with-window-handle-v0-5"] }
Contactbjz
on irc.mozilla.org#rustand#rust-gamedev,orpost an issue on GitHub.
In certain circumstances OpenGL which GLFW uses can conflict with the new handle that thegraphical API is also trying to use, causing crashes, to fix this add
glfw.window_hint(WindowHint::ClientApi(ClientApiHint::NoApi));
before creating the window. If using this however you cannot use certain built-in functions,such aswindow.swap_buffers()
,window.make_current()
, andglfw.set_swap_interval()
, butthese should have equivalents provided by the graphical API.
About
GLFW3 bindings and idiomatic wrapper for Rust.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.