From d59a182448f285685d83b61e5d6092bb70a66ac1 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Fri, 21 Mar 2025 17:05:17 -0500 Subject: [PATCH] rendering with egui and glow works --- crates/client/src/rendering/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/client/src/rendering/mod.rs b/crates/client/src/rendering/mod.rs index d7fe0ffd1e690fcb473c4fa9f38c5a2b02e29825..97ee2545f838c5802ac239c5d98c10f7187b5003 100644 --- a/crates/client/src/rendering/mod.rs +++ b/crates/client/src/rendering/mod.rs @@ -26,6 +26,7 @@ pub struct App { vertex_array: Option, vertex_buffer: Option, element_buffer: Option, + texture_object: Option, #[cfg(not(target_arch = "wasm32"))] gl_surface: Option>, #[cfg(not(target_arch = "wasm32"))] @@ -165,13 +166,16 @@ impl ApplicationHandler for App { glow::UNSIGNED_BYTE, PixelUnpackData::Slice(Some(&image.into_raw()))); gl.generate_mipmap(glow::TEXTURE_2D); - gl.clear_color(1.0, 1.0, 1.0, 1.0); + gl.clear_color(0.0, 0.0, 0.0, 0.0); gl.viewport(0, 0, window.inner_size().width as i32, window.inner_size().height as i32); + gl.enable(glow::BLEND); + gl.blend_func(glow::SRC_ALPHA, glow::ONE_MINUS_SRC_ALPHA); self.program = Some(program); self.vertex_array = Some(vertex_array); self.vertex_buffer = Some(vertex_buffer); self.element_buffer = Some(element_buffer); + self.texture_object = Some(texture); } #[cfg(target_arch = "wasm32")] web_sys::window().unwrap().set_onresize(Some(Closure::::new(move |_| { @@ -221,9 +225,12 @@ impl ApplicationHandler for App { unsafe { gl.clear(glow::COLOR_BUFFER_BIT); + gl.use_program(self.program); + gl.active_texture(glow::TEXTURE0); + gl.bind_texture(glow::TEXTURE_2D, self.texture_object); + gl.bind_vertex_array(self.vertex_array); gl.bind_buffer(glow::ARRAY_BUFFER, self.vertex_buffer); gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, self.element_buffer); - gl.bind_vertex_array(self.vertex_array); gl.draw_elements(glow::TRIANGLES, 6, glow::UNSIGNED_INT, 0); }