GLFW bindings and wrapper for The Rust Programming Language.
extern crate native;
extern crate glfw;
use glfw::Context;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
native::start(argc, argv, main)
}
fn main() {
let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let (window, events) = glfw.create_window(300, 300, "Hello this is window", glfw::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(&window, event);
}
}
}
fn handle_window_event(window: &glfw::Window, event: glfw::WindowEvent) {
match event {
glfw::KeyEvent(glfw::KeyEscape, _, glfw::Press, _) => {
window.set_should_close(true)
}
_ => {}
}
}
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
Add this to your Cargo.toml
:
[dependencies.glfw]
git = "https://github.com/bjz/glfw-rs.git"
Run cargo test
, then ./target/test/<example_name>
.
Contact bjz
on irc.mozilla.org #rust
and #rust-gamedev,
or post an issue on Github.