Giter Site home page Giter Site logo

glfw-rs's Introduction

glfw-rs

GLFW bindings and wrapper for The Rust Programming Language.

Example

extern crate native;
extern crate glfw;

use glfw::Context;

#[start]
fn start(argc: int, argv: **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)
        }
        _ => {}
    }
}

Compilation

Prerequisites

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

Targets

  • make: library, examples, docs
  • make lib: libs only
  • make doc: docs only
  • make examples: build examples
  • make src/examples/<example>.rs: build a specific example
  • make clean: clean up all build files

Cargo-lite

You can use cargo-lite:

cargo-lite.py install --git https://github.com/bjz/glfw-rs.git glfw-rs

Support

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

glfw-rs in use

glfw-rs's People

Contributors

brendanzab avatar emberian avatar ozkriff avatar csherratt avatar sebcrozet avatar alegalle avatar larsbergstrom avatar kimundi avatar metajack avatar hannobraun avatar rlane avatar heroesgrave avatar luqmana avatar h3r2tic avatar bvssvni avatar rubber-duck avatar kmcallister avatar jhasse avatar brson avatar alexanderchr avatar ameyp avatar dustinlacewell avatar leon-vv avatar aeqwa avatar torwegia avatar jmgrosen avatar hami9x avatar phillipwalters avatar zofrex avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.