comparison examples/menu.rs @ 747:8a022334a4c4

menu: Load the title image at frame 60.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 18 Jan 2020 19:47:44 +0100
parents 0ebf6467e4ff
children 31897f650d2d
comparison
equal deleted inserted replaced
746:0ebf6467e4ff 747:8a022334a4c4
114 }); 114 });
115 115
116 let mut surface = GlfwSurface::new(WindowDim::Windowed(640, 480), "Touhou", WindowOpt::default()).expect("GLFW window"); 116 let mut surface = GlfwSurface::new(WindowDim::Windowed(640, 480), "Touhou", WindowOpt::default()).expect("GLFW window");
117 117
118 let image = jpeg_thread.join().expect("image loading"); 118 let image = jpeg_thread.join().expect("image loading");
119 let tex = common::upload_texture_from_rgb_image(&mut surface, image).expect("image loading"); 119 let background = common::upload_texture_from_rgb_image(&mut surface, image).expect("upload data to texture");
120
121 let mut background = match background {
122 LoadedTexture::Rgb(tex) => tex,
123 LoadedTexture::Rgba(tex) => unreachable!(),
124 };
120 125
121 // set the uniform interface to our type so that we can read textures from the shader 126 // set the uniform interface to our type so that we can read textures from the shader
122 let program = 127 let program =
123 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); 128 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings();
124 129
128 .build() 133 .build()
129 .unwrap(); 134 .unwrap();
130 135
131 let mut back_buffer = surface.back_buffer().unwrap(); 136 let mut back_buffer = surface.back_buffer().unwrap();
132 let mut resize = false; 137 let mut resize = false;
138 let mut frame = 0;
133 139
134 'app: loop { 140 'app: loop {
135 for event in surface.poll_events() { 141 for event in surface.poll_events() {
136 match event { 142 match event {
137 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, 143 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app,
147 if resize { 153 if resize {
148 back_buffer = surface.back_buffer().unwrap(); 154 back_buffer = surface.back_buffer().unwrap();
149 resize = false; 155 resize = false;
150 } 156 }
151 157
158 frame += 1;
159 if frame == 60 {
160 let tl_dat = directory.join("TL.DAT");
161 let mut tl_pbg3 = pbg3::from_path_buffered(tl_dat).expect("IN.DAT present");
162 let jpeg = tl_pbg3.get_file("title00.jpg", true).expect("th06logo.jpg in IN.DAT");
163 let image = common::load_from_data(&jpeg).expect("th06logo.jpg decodable");
164 common::reupload_texture_from_rgb_image(&mut background, image).expect("upload data to texture");
165 }
166
152 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU 167 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU
153 // and use it in the shader 168 // and use it in the shader
154 surface 169 surface
155 .pipeline_builder() 170 .pipeline_builder()
156 .pipeline(&back_buffer, &PipelineState::default(), |pipeline, mut shd_gate| { 171 .pipeline(&back_buffer, &PipelineState::default(), |pipeline, mut shd_gate| {
157 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader 172 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader
158 let bound_tex = match &tex { 173 let tex = pipeline.bind_texture(&background);
159 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex),
160 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex),
161 };
162 174
163 shd_gate.shade(&program, |iface, mut rdr_gate| { 175 shd_gate.shade(&program, |iface, mut rdr_gate| {
164 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU 176 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU
165 // to use the texture passed as argument (no allocation or copy is performed) 177 // to use the texture passed as argument (no allocation or copy is performed)
166 iface.color_map.update(&bound_tex); 178 iface.color_map.update(&tex);
167 let mvp = ortho_2d(0., 640., 480., 0.); 179 let mvp = ortho_2d(0., 640., 480., 0.);
168 // TODO: check how to pass by reference. 180 // TODO: check how to pass by reference.
169 iface.mvp.update(*mvp.borrow_inner()); 181 iface.mvp.update(*mvp.borrow_inner());
170 182
171 let render_state = RenderState::default() 183 let render_state = RenderState::default()