#opengl #wasm

uni-gl

Unrust native/wasm openGL compatibility layer

3 releases

new 0.1.2 Nov 30, 2019
0.1.1 Feb 1, 2019
0.1.0 Aug 3, 2018

#55 in WebAssembly

Download history 21/week @ 2019-08-17 6/week @ 2019-08-24 9/week @ 2019-08-31 11/week @ 2019-09-07 36/week @ 2019-09-14 14/week @ 2019-09-21 5/week @ 2019-09-28 3/week @ 2019-10-05 6/week @ 2019-10-12 7/week @ 2019-10-19 44/week @ 2019-10-26 14/week @ 2019-11-02 3/week @ 2019-11-09 12/week @ 2019-11-16 28/week @ 2019-11-23

64 downloads per month
Used in 3 crates (2 directly)

MIT license

94KB
2K SLoC

unrust / uni-gl

Build Status Documentation crates.io

This library is a part of Unrust, a pure rust native/wasm game engine. This library provides a native/wasm compatibility layer for following components :

  • OpenGL API

When used in conjonction with uni-app, on native target, it provides an OpenGL 3.2+ or OpenGLES 2.0+ Core Profile context. On web target, it provides a WebGL 2.0 context where available, else a WebGL 1.0 context.

This project is under heavily development, all api are very unstable until version 0.2

Usage

[dependencies]
uni-app="0.1.*"
uni-gl="0.1.*"
extern crate uni_app;
extern crate uni_gl;

fn main() {
    // create the game window (native) or canvas (web)
    let app = uni_app::App::new(uni_app::AppConfig {
        size: (800, 600),
        title: "my game".to_owned(),
        vsync: true,
        show_cursor: true,
        headless: false,
        resizable: true,
        fullscreen: false,
    });
    // retrieve the opengl context
    let gl = uni_gl::WebGLRenderingContext::new(app.canvas());
    // start game loop
    app.run(move |_app: &mut uni_app::App| {
        // do some openGL stuff
        gl.clear_color(0.0, 0.0, 1.0, 1.0);
        gl.clear(uni_gl::BufferBit::Color);
    });
}

Build

As web app (wasm32-unknown-unknown)

When targetting wasm32-unknown-unknown, stdweb currently requires Rust nightly.

cargo install --force cargo-web # installs web sub command
rustup override set nightly
rustup target install wasm32-unknown-unknown
cargo web start --example basic --release

As desktop app (native-opengl)

Native compilation works with current stable Rust (1.28)

rustup override set stable
cargo run --example basic --release

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–560KB
~11K SLoC