Updated to use model refs in scene graph
Switched default scene to an unnecessarily large number of boxes
Getty Ritter
9 years ago
| 9 | 9 |
const VERTEX_SHADER: &'static str = include_str!("../data/shaders/vertex.glsl");
|
| 10 | 10 |
const FRAGMENT_SHADER: &'static str = include_str!("../data/shaders/fragment.glsl");
|
| 11 | 11 |
|
| 12 | |
pub struct Graphics {
|
| 12 |
pub struct Graphics<'a> {
|
| 13 | 13 |
disp: Display,
|
| 14 | 14 |
rt: f32,
|
| 15 | 15 |
light: [f32;3],
|
| 16 | |
graph: SceneGraph,
|
| 16 |
graph: SceneGraph<'a>,
|
| 17 | 17 |
program: Program,
|
| 18 | 18 |
tex: Texture2d,
|
| 19 | 19 |
}
|
|
| 30 | 30 |
}
|
| 31 | 31 |
|
| 32 | 32 |
|
| 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 {
|
| 35 | 35 |
let disp = WindowBuilder::new()
|
| 36 | 36 |
.with_title(format!("utmyen"))
|
| 37 | 37 |
.with_depth_buffer(24)
|
|
| 42 | 42 |
VERTEX_SHADER,
|
| 43 | 43 |
FRAGMENT_SHADER,
|
| 44 | 44 |
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();
|
| 49 | 50 |
Graphics {
|
| 50 | 51 |
disp: disp,
|
| 51 | 52 |
rt: 0.0,
|
| 52 | 53 |
light: [-1.0, 0.4, 0.9f32],
|
| 53 | |
graph: SceneGraph::Translate(0.0,0.0,1.0,Box::new(sg)),
|
| 54 |
graph: sg,
|
| 54 | 55 |
program: program,
|
| 55 | 56 |
tex: tex,
|
| 56 | 57 |
}
|
| 32 | 32 |
let md = sample();
|
| 33 | 33 |
let tex = sample_texture();
|
| 34 | 34 |
|
| 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)));
|
| 39 | 45 |
|
| 40 | 46 |
let mut g = graphics::Graphics::new(graph, tex);
|
| 41 | 47 |
|