Skip to content

johann2/glfw-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

glfw-rs

GLFW bindings and wrapper for The Rust Programming Language.

Example code

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);
    }
}

Compilation

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 ..

Building everything

make 

Building the library

make lib

Building the examples

make examples

Or to build a single example:

make <example-name>

FAQ

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.

glfw-rs in use

Support

Contact bjz on irc.mozilla.org #rust and #rust-gamedev, or post an issue on Github.

About

GLFW3 bindings and idiomatic wrapper for Rust.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%