GLFW bindings and wrapper for The Rust Programming Language.
extern mod native;
extern mod glfw;
#[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
do glfw::start {
// 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);
}
}
You will need CMake to set up glfw-rs for building.
First setup your build directory:
git clone https://github.com/bjz/glfw-rs.git
cd glfw-rs
mkdir build
cd build
cmake ..
make
make lib
make examples
Or to build a single example:
make <example-name>
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.