@@ 26,6 26,7 @@ pub struct App {
vertex_array: Option<glow::VertexArray>,
vertex_buffer: Option<glow::Buffer>,
element_buffer: Option<glow::Buffer>,
+ texture_object: Option<glow::Texture>,
#[cfg(not(target_arch = "wasm32"))]
gl_surface: Option<Surface<WindowSurface>>,
#[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::<dyn Fn(Event)>::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);
}