pfff
This commit is contained in:
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