GLFW bindings and wrapper for The Rust Programming Language.
extern crate native;
extern crate glfw = "glfw-rs";
#[start]
fn start(argc: int, argv: **u8) -> int {
// Run GLFW on the main thread
native::start(argc, argv, main)
}
fn main() {
// Set up an error callback
glfw::set_error_callback(~ErrorContext);
// Initialize the library
glfw::start(proc() {
// Create a windowed mode window and its OpenGL context
let window = glfw::Window::create(300, 300, "Hello this is window", glfw::Windowed)
.expect("Failed to create GLFW window.");
// Make the window's context current
window.make_context_current();
// Loop until the user closes the window
while !window.should_close() {
// Swap front and back buffers
window.swap_buffers();
// Poll for and process events
glfw::poll_events();
}
});
}
struct ErrorContext;
impl glfw::ErrorCallback for ErrorContext {
fn call(&self, _: glfw::Error, description: ~str) {
println!("GLFW Error: {:s}", description);
}
}
To build glfw-rs you will need to build glfw using the BUILD_SHARED_LIBS option.
Once you have built glfw-rs you might encouter the following error when running the examples: 'error while loading shared libraries: libglfw.so.3: ... '
Read the last part of this article for information on how to fix this.
You can use cargo-lite:
cargo-lite.py install --git https://github.com/bjz/glfw-rs.git glfw-rs
Or use make manually to build the library and docs:
make
To build the examples:
make examples
Or a specific example:
make src/examples/window.rs
make install
To install to a custom location, override the INSTALL_DIR
variable:
make install INSTALL_DIR=custom/location
I get lots of errors like: undefined reference to 'glfwSetScrollCallback'
glfw-rs wraps glfw 3.0. Version 2.7 was out for a long time, and may still be hanging around on package managers. If you encounter these kinds of errors, make sure you version of glfw is up to date.
Ok, so I have windowing sorted, now where do I find OpenGL?
You can use the function pointer loader, gl-rs, or the OpenGL-ES bindings.
Contact bjz
on irc.mozilla.org #rust
and #rust-gamedev,
or post an issue on Github.