gdritter repos utmyen / bd8cffb
Updated to use model refs in scene graph Switched default scene to an unnecessarily large number of boxes Getty Ritter 8 years ago
2 changed file(s) with 20 addition(s) and 13 deletion(s). Collapse all Expand all
99 const VERTEX_SHADER: &'static str = include_str!("../data/shaders/vertex.glsl");
1010 const FRAGMENT_SHADER: &'static str = include_str!("../data/shaders/fragment.glsl");
1111
12 pub struct Graphics {
12 pub struct Graphics<'a> {
1313 disp: Display,
1414 rt: f32,
1515 light: [f32;3],
16 graph: SceneGraph,
16 graph: SceneGraph<'a>,
1717 program: Program,
1818 tex: Texture2d,
1919 }
3030 }
3131
3232
33 impl Graphics {
34 pub fn new(sg: SceneGraph, t: RawImage2d<u8>) -> Self {
33 impl<'a> Graphics<'a> {
34 pub fn new(sg: SceneGraph<'a>, t: RawImage2d<u8>) -> Self {
3535 let disp = WindowBuilder::new()
3636 .with_title(format!("utmyen"))
3737 .with_depth_buffer(24)
4242 VERTEX_SHADER,
4343 FRAGMENT_SHADER,
4444 None).unwrap();
45 let tex = Texture2d::with_format(&disp,
46 t,
47 glium::texture::UncompressedFloatFormat::U8U8U8,
48 glium::texture::MipmapsOption::NoMipmap).unwrap();
45 let tex = Texture2d::with_format(
46 &disp,
47 t,
48 glium::texture::UncompressedFloatFormat::U8U8U8,
49 glium::texture::MipmapsOption::NoMipmap).unwrap();
4950 Graphics {
5051 disp: disp,
5152 rt: 0.0,
5253 light: [-1.0, 0.4, 0.9f32],
53 graph: SceneGraph::Translate(0.0,0.0,1.0,Box::new(sg)),
54 graph: sg,
5455 program: program,
5556 tex: tex,
5657 }
3232 let md = sample();
3333 let tex = sample_texture();
3434
35 let graph = SceneGraph::Many(vec![
36 SceneGraph::Model(md.clone()),
37 SceneGraph::Translate(-0.3,0.0,-0.3, Box::new(SceneGraph::Model(md.clone())))
38 ]);
35 let mut v = vec![];
36 for x in -20..20i32 {
37 for y in -20..20i32 {
38 v.push(SceneGraph::Translate(x as f32*0.3,
39 0.0,
40 y as f32*0.3,
41 Box::new(SceneGraph::Model(&md))));
42 }
43 }
44 let graph = SceneGraph::Translate(0.0,0.0,1.0,Box::new(SceneGraph::Many(v)));
3945
4046 let mut g = graphics::Graphics::new(graph, tex);
4147