pfff
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -138,3 +138,8 @@ Cargo.lock
|
|||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
29
beppe_online/Cargo.toml
Normal file
29
beppe_online/Cargo.toml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
[package]
|
||||||
|
name = "beppe_online"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
authors = ["Beppe Vanrolleghem beppe.vanrolleghem@gmail.com"]
|
||||||
|
description = "Testing out wasm"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
wasm-bindgen = "0.2"
|
||||||
|
js-sys = "0.3"
|
||||||
|
|
||||||
|
[dependencies.web-sys]
|
||||||
|
version = "0.3"
|
||||||
|
features = [
|
||||||
|
'Document',
|
||||||
|
'Window',
|
||||||
|
'HtmlCanvasElement',
|
||||||
|
'WebGlRenderingContext',
|
||||||
|
'WebGl2RenderingContext',
|
||||||
|
'WebGlProgram',
|
||||||
|
'WebGlShader',
|
||||||
|
'WebGlBuffer',
|
||||||
|
'WebGlUniformLocation'
|
||||||
|
]
|
27
beppe_online/src/lib.rs
Normal file
27
beppe_online/src/lib.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::JsCast;
|
||||||
|
use web_sys::{WebGlRenderingContext, WebGlShader, WebGlProgram};
|
||||||
|
extern crate js_sys;
|
||||||
|
|
||||||
|
pub fn init_webgl_context(canvas_id: &str) -> Result<WebGlRenderingContext, JsValue> {
|
||||||
|
let document = web_sys::window().unwrap().document().unwrap();
|
||||||
|
let canvas = document.get_element_by_id(canvas_id).unwrap();
|
||||||
|
let canvas: web_sys::HtmlCanvasElement = canvas.dyn_into::<web_sys::HtmlCanvasElement>()?;
|
||||||
|
let gl: WebGlRenderingContext = canvas.get_context("webgl")?
|
||||||
|
.unwrap()
|
||||||
|
.dyn_into::<WebGlRenderingContext>()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
gl.viewport(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
canvas.width().try_into().unwrap(),
|
||||||
|
canvas.height().try_into().unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(gl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// https://blog.logrocket.com/implement-webassembly-webgl-viewer-using-rust/#setup-environment
|
||||||
|
pub fn create_
|
Reference in New Issue
Block a user