gdritter repos utmyen / 5077a3c
Added two more models to default view for now Getty Ritter 8 years ago
2 changed file(s) with 49 addition(s) and 16 deletion(s). Collapse all Expand all
3434 VERTEX_SHADER,
3535 FRAGMENT_SHADER,
3636 None).unwrap();
37 let tex = Texture2d::new(&disp, t).unwrap();
37 let tex = Texture2d::with_format(&disp,
38 t,
39 glium::texture::UncompressedFloatFormat::U8U8U8,
40 glium::texture::MipmapsOption::NoMipmap).unwrap();
3841 Graphics {
3942 disp: disp,
4043 rt: 0.0,
4144 px: 0.0,
42 py: 0.0,
45 py: 0.01,
4346 pz: 0.0,
4447 light: [-1.0, 0.4, 0.9f32],
4548 model: m,
6568 24 => self.rt -= 0.1,
6669 25 => self.py -= DX,
6770 26 => self.rt += 0.1,
68 38 => self.px -= DX,
71 38 => self.px += DX,
6972 39 => self.py += DX,
70 40 => self.px += DX,
73 40 => self.px -= DX,
7174 44 => self.pz -= DX,
7275 45 => self.pz += DX,
7376 _ => {},
8891
8992 impl<'a> Target<'a> {
9093 fn step(&mut self, g: &mut Graphics) -> bool {
91 let uniforms = uniform! {
92 perspective: self.perspective(),
93 u_light: g.light,
94 matrix: self.matrix(g),
95 tx: &g.tex,
96 };
9794
9895 let params = glium::DrawParameters {
9996 depth: glium::Depth {
107104 let vbuf = g.model.get_vbuf(&g.disp);
108105 let idxs = g.model.get_ibuf(&g.disp);
109106 self.frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
107
108 let per = self.perspective();
109 let m1 = self.matrix(g, g.px, g.py);
110 let m2 = self.matrix(g, g.px+0.01, g.py);
111 let m3 = self.matrix(g, g.px-0.01, g.py);
112
113 let mytex = glium::uniforms::Sampler::new(&g.tex)
114 .minify_filter(glium::uniforms::MinifySamplerFilter::Nearest)
115 .magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest);
116
110117 self.frame.draw(&vbuf,
111118 &idxs,
112119 &g.program,
113 &uniforms,
120 &uniform! {
121 perspective: per,
122 u_light: g.light,
123 matrix: m1,
124 tx: mytex,
125 },
114126 &params).unwrap();
127
128 self.frame.draw(&vbuf,
129 &idxs,
130 &g.program,
131 &uniform! {
132 perspective: per,
133 u_light: g.light,
134 matrix: m2,
135 tx: mytex,
136 },
137 &params).unwrap();
138
139 self.frame.draw(&vbuf,
140 &idxs,
141 &g.program,
142 &uniform! {
143 perspective: per,
144 u_light: g.light,
145 matrix: m3,
146 tx: mytex,
147 },
148 &params).unwrap();
149
115150 return true;
116151 }
117152
118 fn matrix(&self, g: &Graphics) -> [[f32;4];4] {
153 fn matrix(&self, g: &Graphics, px: f32, py: f32) -> [[f32;4];4] {
119154 let rt = g.rt;
120 let px = g.px;
121 let py = g.py;
122155 let pz = g.pz;
123156 [ [ rt.cos() * SX, 0.0, -rt.sin() * SX, 0.0 ],
124157 [ 0.0, SX, 0.0, 0.0 ],
1010
1111 fn sample() -> model::Model {
1212 let file = std::env::args().nth(1)
13 .unwrap_or("data/test/monkey.utm".to_string());
13 .unwrap_or("data/test/chest.utm".to_string());
1414 model::Model::load_from_file(&file).unwrap()
1515 }
1616
1717 fn sample_texture<'a>() -> RawImage2d<'a, u8> {
1818 use std::io::Cursor;
1919 let img = image::load(
20 Cursor::new(&include_bytes!("../data/test/rainbow.png")[..]),
20 Cursor::new(&include_bytes!("/home/gdritter/documents/pixel-chest.png")[..]),
2121 image::PNG).unwrap().to_rgba();
2222 let dims = img.dimensions();
2323 let img = glium::texture::RawImage2d::from_raw_rgba_reversed(img.into_raw(), dims);