Mercurial > touhou
annotate examples/eclrenderer.rs @ 658:3a9d82a02c88
Add a contructor for enemy, and a new example.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 10 Aug 2019 12:48:01 +0200 |
parents | |
children | 31fc0d881105 |
rev | line source |
---|---|
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 use image::GenericImageView; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 use luminance::context::GraphicsContext; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 use luminance::framebuffer::Framebuffer; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 use luminance::pipeline::BoundTexture; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 use luminance::pixel::{NormRGB8UI, Floating}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 use luminance::render_state::RenderState; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 use luminance::shader::program::{Program, Uniform}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 use luminance::tess::{Mode, TessBuilder}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 use luminance::texture::{Dim2, Flat, Sampler, Texture, GenMipmaps}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 use luminance_derive::{Semantics, Vertex, UniformInterface}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 use luminance_glfw::event::{Action, Key, WindowEvent}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 use luminance_glfw::surface::{GlfwSurface, Surface, WindowDim, WindowOpt}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 use touhou::th06::anm0::Anm0; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 use touhou::th06::anm0_vm::{Sprite, Vertex as FakeVertex}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 use touhou::th06::ecl::Ecl; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 use touhou::th06::enemy::{Enemy, Game, Position}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 use touhou::util::math::{perspective, setup_camera}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 use touhou::util::prng::Prng; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 use std::cell::RefCell; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 use std::fs::File; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 use std::io::{BufReader, Read}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 use std::rc::Rc; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 use std::env; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 use std::path::Path; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 const VS: &str = r#" |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 in ivec3 in_position; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 in vec2 in_texcoord; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 in uvec4 in_color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 uniform mat4 mvp; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 out vec2 texcoord; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 out vec4 color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 void main() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 gl_Position = mvp * vec4(vec3(in_position), 1.0); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 texcoord = vec2(in_texcoord); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 // Normalized from the u8 being passed. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 color = vec4(in_color) / 255.; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 "#; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 const FS: &str = r#" |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 in vec2 texcoord; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 in vec4 color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 uniform sampler2D color_map; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 out vec4 frag_color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 void main() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 frag_color = texture(color_map, texcoord) * color; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 "#; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 #[derive(Clone, Copy, Debug, Eq, PartialEq, Semantics)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 pub enum Semantics { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 #[sem(name = "in_position", repr = "[i16; 3]", wrapper = "VertexPosition")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 Position, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 #[sem(name = "in_texcoord", repr = "[f32; 2]", wrapper = "VertexTexcoord")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 Texcoord, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 #[sem(name = "in_color", repr = "[u8; 4]", wrapper = "VertexColor")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 Color, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 #[repr(C)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 #[derive(Clone, Copy, Debug, PartialEq, Vertex)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 #[vertex(sem = "Semantics")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 struct Vertex { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 pos: VertexPosition, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 uv: VertexTexcoord, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 rgba: VertexColor, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 #[derive(UniformInterface)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 struct ShaderInterface { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 // the 'static lifetime acts as “anything” here |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 color_map: Uniform<&'static BoundTexture<'static, Flat, Dim2, Floating>>, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 #[uniform(name = "mvp")] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 mvp: Uniform<[[f32; 4]; 4]>, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 fn main() { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 // Parse arguments. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 let args: Vec<_> = env::args().collect(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 if args.len() != 5 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 eprintln!("Usage: {} <ECL file> <sub number> <ANM file> <PNG file>", args[0]); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 return; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 let ecl_filename = &args[1]; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 let sub = args[2].parse().expect("number"); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 let anm_filename = &args[3]; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 let png_filename = &args[4]; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 // Open the ECL file. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 let file = File::open(ecl_filename).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 let mut file = BufReader::new(file); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 let mut buf = vec![]; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 file.read_to_end(&mut buf).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 let (_, ecl) = Ecl::from_slice(&buf).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 // Open the ANM file. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 let file = File::open(anm_filename).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 let mut file = BufReader::new(file); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 let mut buf = vec![]; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 file.read_to_end(&mut buf).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 let anm0 = Anm0::from_slice(&buf).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 let anm0 = Rc::new(RefCell::new(anm0)); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 if ecl.subs.len() < sub { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 eprintln!("This ecl doesn’t contain a sub named {}.", sub); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 return; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 // TODO: seed this PRNG with a valid seed. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 let prng = Rc::new(RefCell::new(Prng::new(0))); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 // Create the Game god object. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 let game = Game::new(prng); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 let game = Rc::new(RefCell::new(game)); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 // And the enemy object. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 let mut enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 enemy.set_anim(0); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 let vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() }; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 // Open the image atlas matching this ANM. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 let tex = load_from_disk(&mut surface, Path::new(png_filename)).expect("texture loading"); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 // set the uniform interface to our type so that we can read textures from the shader |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 let (program, _) = |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation"); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 let mut tess = TessBuilder::new(&mut surface) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 .add_vertices(vertices) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 .set_mode(Mode::TriangleFan) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 .build() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 .unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 let mut back_buffer = Framebuffer::back_buffer(surface.size()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 let mut frame = 0; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 'app: loop { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 for event in surface.poll_events() { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
156 match event { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 WindowEvent::FramebufferSize(width, height) => { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 back_buffer = Framebuffer::back_buffer([width as u32, height as u32]); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
161 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 _ => (), |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 if frame == 60 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 break; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
170 frame += 1; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 let mut slice = tess |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 .as_slice_mut() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 .unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 let mut game = game.borrow_mut(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 game.run_frame(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 let sprites = game.get_sprites(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 fill_vertices_ptr(sprites, slice.as_mut_ptr()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
182 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 // and use it in the shader |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
185 surface |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
186 .pipeline_builder() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, shd_gate| { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 let bound_tex = pipeline.bind_texture(&tex); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
191 shd_gate.shade(&program, |rdr_gate, iface| { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
193 // to use the texture passed as argument (no allocation or copy is performed) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
194 iface.color_map.update(&bound_tex); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
195 //let mvp = ortho_2d(0., 384., 448., 0.); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 let proj = perspective(0.5235987755982988, 384. / 448., 101010101./2010101., 101010101./10101.); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 let view = setup_camera(0., 0., 1.); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
198 let mvp = view * proj; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
199 //println!("{:#?}", mvp); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
200 // TODO: check how to pass by reference. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
201 iface.mvp.update(*mvp.borrow_inner()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
202 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
203 rdr_gate.render(RenderState::default(), |tess_gate| { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 // render the tessellation to the surface the regular way and let the vertex shader’s |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 // magic do the rest! |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 tess_gate.render(&mut surface, (&tess).into()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
207 }); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 }); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 }); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
210 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 surface.swap_buffers(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
212 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 fn fill_vertices_ptr(sprites: Vec<Rc<RefCell<Sprite>>>, vertices: *mut Vertex) { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
216 let mut fake_vertices = unsafe { std::mem::transmute::<*mut Vertex, &mut [FakeVertex; 4]>(vertices) }; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
217 for sprite in sprites { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
218 let sprite = sprite.borrow(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 sprite.fill_vertices(&mut fake_vertices); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 fn load_from_disk(surface: &mut GlfwSurface, path: &Path) -> Option<Texture<Flat, Dim2, NormRGB8UI>> { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 // load the texture into memory as a whole bloc (i.e. no streaming) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 match image::open(&path) { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 Ok(img) => { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 let (width, height) = img.dimensions(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 let texels = img |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 .pixels() |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 .map(|(x, y, rgb)| (rgb[0], rgb[1], rgb[2])) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 .collect::<Vec<_>>(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 // create the luminance texture; the third argument is the number of mipmaps we want (leave it |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 // to 0 for now) and the latest is a the sampler to use when sampling the texels in the |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 // shader (we’ll just use the default one) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 let tex = |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 Texture::new(surface, [width, height], 0, &Sampler::default()).expect("luminance texture creation"); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 // the first argument disables mipmap generation (we don’t care so far) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 tex.upload(GenMipmaps::No, &texels); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 Some(tex) |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 Err(e) => { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 eprintln!("cannot open image {}: {}", path.display(), e); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 None |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
250 } |