extern crate core;
#[macro_use]
extern crate glium;
extern crate image;
extern crate therm_model;
extern crate therm_util;

mod graphics;

use glium::texture::{RawImage2d,Texture2dDataSource};
use therm_model::farbfeld::FFImage;
use therm_model::model;
use therm_model::graph::SceneGraph;

fn sample() -> model::Model {
    let file = std::env::args().nth(1)
        .unwrap_or("data/test/chest.utm".to_string());
    model::Model::load_from_file(&file).unwrap()
}

fn sample_texture<'a>() -> RawImage2d<'a, (u16,u16,u16,u16)> {
    FFImage::from_bz2_file("data/test/chest.ff.bz2").unwrap().into_raw()
}

fn main() {
    let md = sample();
    let tex = sample_texture();

    let mut v = vec![];
    for x in -50..5i32 {
        for y in -5..5i32 {
            v.push(SceneGraph::Translate(x as f32*0.3,
                                         0.0,
                                         y as f32*0.3,
                                         Box::new(SceneGraph::Model(&md))));
        }
    }
    let graph = SceneGraph::Translate(0.0,0.0,1.0,Box::new(SceneGraph::Many(v)));

    let mut g = graphics::Graphics::new(graph, tex);

    g.run();
}
