# HG changeset patch # User Emmanuel Gil Peyrot # Date 1579373264 -3600 # Node ID 8a022334a4c445cd4a28cb4506795fe5bdef0e9b # Parent 0ebf6467e4ffb66abee76bc3525f43261f3fb388 menu: Load the title image at frame 60. diff --git a/examples/menu.rs b/examples/menu.rs --- a/examples/menu.rs +++ b/examples/menu.rs @@ -116,7 +116,12 @@ fn main() { let mut surface = GlfwSurface::new(WindowDim::Windowed(640, 480), "Touhou", WindowOpt::default()).expect("GLFW window"); let image = jpeg_thread.join().expect("image loading"); - let tex = common::upload_texture_from_rgb_image(&mut surface, image).expect("image loading"); + let background = common::upload_texture_from_rgb_image(&mut surface, image).expect("upload data to texture"); + + let mut background = match background { + LoadedTexture::Rgb(tex) => tex, + LoadedTexture::Rgba(tex) => unreachable!(), + }; // set the uniform interface to our type so that we can read textures from the shader let program = @@ -130,6 +135,7 @@ fn main() { let mut back_buffer = surface.back_buffer().unwrap(); let mut resize = false; + let mut frame = 0; 'app: loop { for event in surface.poll_events() { @@ -149,21 +155,27 @@ fn main() { resize = false; } + frame += 1; + if frame == 60 { + let tl_dat = directory.join("TL.DAT"); + let mut tl_pbg3 = pbg3::from_path_buffered(tl_dat).expect("IN.DAT present"); + let jpeg = tl_pbg3.get_file("title00.jpg", true).expect("th06logo.jpg in IN.DAT"); + let image = common::load_from_data(&jpeg).expect("th06logo.jpg decodable"); + common::reupload_texture_from_rgb_image(&mut background, image).expect("upload data to texture"); + } + // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU // and use it in the shader surface .pipeline_builder() .pipeline(&back_buffer, &PipelineState::default(), |pipeline, mut shd_gate| { // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader - let bound_tex = match &tex { - LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), - LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), - }; + let tex = pipeline.bind_texture(&background); shd_gate.shade(&program, |iface, mut rdr_gate| { // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU // to use the texture passed as argument (no allocation or copy is performed) - iface.color_map.update(&bound_tex); + iface.color_map.update(&tex); let mvp = ortho_2d(0., 640., 480., 0.); // TODO: check how to pass by reference. iface.mvp.update(*mvp.borrow_inner());