Mercurial > touhou
comparison examples/eclrenderer.rs @ 742:0a250ddfae79
examples: Update luminance.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 07 Jan 2020 00:23:15 +0100 |
parents | d5d5496e4e53 |
children | 0fed350d1778 |
comparison
equal
deleted
inserted
replaced
741:3555845f8cf4 | 742:0a250ddfae79 |
---|---|
1 use luminance::blending::{Equation, Factor}; | 1 use luminance::blending::{Equation, Factor}; |
2 use luminance::context::GraphicsContext; | 2 use luminance::context::GraphicsContext; |
3 use luminance::pipeline::BoundTexture; | 3 use luminance::pipeline::{BoundTexture, PipelineState}; |
4 use luminance::pixel::NormUnsigned; | 4 use luminance::pixel::NormUnsigned; |
5 use luminance::render_state::RenderState; | 5 use luminance::render_state::RenderState; |
6 use luminance::shader::program::{Program, Uniform}; | 6 use luminance::shader::program::{Program, Uniform}; |
7 use luminance::tess::{Mode, TessBuilder}; | 7 use luminance::tess::{Mode, TessBuilder}; |
8 use luminance::texture::{Dim2, Flat}; | 8 use luminance::texture::{Dim2, Flat}; |
106 | 106 |
107 // Open the ANM file. | 107 // Open the ANM file. |
108 let buf = load_file_into_vec(anm_filename); | 108 let buf = load_file_into_vec(anm_filename); |
109 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); | 109 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); |
110 let anm0 = anms.pop().unwrap(); | 110 let anm0 = anms.pop().unwrap(); |
111 let anm0 = Rc::new(RefCell::new(anm0)); | 111 let anm0 = Rc::new(RefCell::new([anm0.clone(), anm0])); |
112 | 112 |
113 if ecl.subs.len() < sub as usize { | 113 if ecl.subs.len() < sub as usize { |
114 eprintln!("This ecl doesn’t contain a sub named {}.", sub); | 114 eprintln!("This ecl doesn’t contain a sub named {}.", sub); |
115 return; | 115 return; |
116 } | 116 } |
122 // Create the Game god object. | 122 // Create the Game god object. |
123 let game = Game::new(prng, rank); | 123 let game = Game::new(prng, rank); |
124 let game = Rc::new(RefCell::new(game)); | 124 let game = Rc::new(RefCell::new(game)); |
125 | 125 |
126 // And the enemy object. | 126 // And the enemy object. |
127 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); | 127 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, false, Rc::downgrade(&anm0), Rc::downgrade(&game)); |
128 let mut ecl_runner = EclRunner::new(&ecl, enemy.clone(), sub); | 128 let mut ecl_runner = EclRunner::new(&ecl, enemy.clone(), sub); |
129 | 129 |
130 assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); | 130 assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); |
131 let vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() }; | 131 let vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() }; |
132 | 132 |
133 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); | 133 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); |
134 | 134 |
135 // Open the image atlas matching this ANM. | 135 // Open the image atlas matching this ANM. |
136 let tex = load_anm_image(&mut surface, &anm0.borrow(), anm_filename).expect("image loading"); | 136 let tex = load_anm_image(&mut surface, &anm0.borrow()[0], &anm_filename).expect("image loading"); |
137 | 137 |
138 // set the uniform interface to our type so that we can read textures from the shader | 138 // set the uniform interface to our type so that we can read textures from the shader |
139 let program = | 139 let program = |
140 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); | 140 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); |
141 | 141 |
188 | 188 |
189 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU | 189 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU |
190 // and use it in the shader | 190 // and use it in the shader |
191 surface | 191 surface |
192 .pipeline_builder() | 192 .pipeline_builder() |
193 .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { | 193 .pipeline(&back_buffer, &PipelineState::default(), |pipeline, mut shd_gate| { |
194 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader | 194 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader |
195 let bound_tex = match &tex { | 195 let bound_tex = match &tex { |
196 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), | 196 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), |
197 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), | 197 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), |
198 }; | 198 }; |
210 iface.mvp.update(*mvp.borrow_inner()); | 210 iface.mvp.update(*mvp.borrow_inner()); |
211 | 211 |
212 let render_state = RenderState::default() | 212 let render_state = RenderState::default() |
213 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); | 213 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); |
214 | 214 |
215 rdr_gate.render(render_state, |mut tess_gate| { | 215 rdr_gate.render(&render_state, |mut tess_gate| { |
216 // render the tessellation to the surface the regular way and let the vertex shader’s | 216 // render the tessellation to the surface the regular way and let the vertex shader’s |
217 // magic do the rest! | 217 // magic do the rest! |
218 tess_gate.render(&tess); | 218 tess_gate.render(&tess); |
219 }); | 219 }); |
220 }); | 220 }); |