Crates.io | uni-gl |
lib.rs | uni-gl |
version | 0.2.1 |
source | src |
created_at | 2018-08-03 18:13:22.702068 |
updated_at | 2022-10-11 08:45:36.196227 |
description | Unrust native/wasm openGL/webGL compatibility layer |
homepage | |
repository | https://github.com/unrust/uni-gl |
max_upload_size | |
id | 77377 |
size | 140,014 |
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 :
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.
[dependencies]
uni-app="0.2.*"
uni-gl="0.2.*"
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,
intercept_close_request: 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);
});
}
Install wasm32 target :
rustup target install wasm32-unknown-unknown
Compile the demo with
wasm-pack build examples
This creates a wasm package in examples/pkg
Run the demo with
cd www
npm install
npm run start
Open your browser at http://localhost:8080/
cargo run --example basic --release
Licensed under either of
at your option.
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.