From 7f52e3939b23748e36927a3749eaaa5a6cd0278e Mon Sep 17 00:00:00 2001 From: Speykious Date: Wed, 31 Jan 2024 23:41:19 +0100 Subject: [PATCH] Fix WebGL scene sizing and style --- examples/render-webgl/index.html | 25 +++++++++++++++++++++++++ examples/render-webgl/src/main.rs | 21 +++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/examples/render-webgl/index.html b/examples/render-webgl/index.html index d5ca449..2e722d0 100644 --- a/examples/render-webgl/index.html +++ b/examples/render-webgl/index.html @@ -8,6 +8,31 @@ Inox2D WebGL Example + + diff --git a/examples/render-webgl/src/main.rs b/examples/render-webgl/src/main.rs index c81fd3f..f14fcd2 100644 --- a/examples/render-webgl/src/main.rs +++ b/examples/render-webgl/src/main.rs @@ -63,15 +63,16 @@ async fn run() -> Result<(), Box> { let context_options = js_sys::Object::new(); js_sys::Reflect::set(&context_options, &"stencil".into(), &true.into()).unwrap(); + let canvas = web_sys::window() + .unwrap() + .document() + .unwrap() + .get_element_by_id("canvas") + .unwrap() + .dyn_into::() + .unwrap(); + let gl = { - let canvas = web_sys::window() - .unwrap() - .document() - .unwrap() - .get_element_by_id("canvas") - .unwrap() - .dyn_into::() - .unwrap(); let webgl2_context = canvas .get_context_with_context_options("webgl2", &context_options) .unwrap() @@ -91,12 +92,10 @@ async fn run() -> Result<(), Box> { let model = parse_inp(model_bytes.as_ref())?; info!("Initializing Inox2D renderer"); - let window_size = window.inner_size(); let mut renderer = OpenglRenderer::new(gl)?; info!("Creating buffers and uploading model textures"); renderer.prepare(&model)?; - renderer.resize(window_size.width, window_size.height); renderer.camera.scale = Vec2::splat(0.15); info!("Inox2D renderer initialized"); @@ -145,6 +144,8 @@ async fn run() -> Result<(), Box> { WindowEvent::Resized(physical_size) => { // Handle window resizing renderer.borrow_mut().resize(physical_size.width, physical_size.height); + canvas.set_width(physical_size.width); + canvas.set_height(physical_size.height); window.request_redraw(); } WindowEvent::CloseRequested => elwt.exit(),