Texture example use Loader
@@ -14,9 +14,13 @@ fn main() {
let mut camera = Camera::new_perspective(&gl, vec3(4.0, 1.5, 4.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 1.0, 0.0),
degrees(45.0), width as f32 / height as f32, 0.1, 1000.0);
+ let mut loader = Loader::new();
+ loader.start_loading("examples/assets/models/penguin.3d");
+ loader.start_loading("examples/assets/textures/test_texture.jpg");
+ loader.wait_all(move |loaded| {
let box_mesh = tri_mesh::MeshBuilder::new().unconnected_cube().build().unwrap();
let texture = texture::Texture2D::new_from_bytes(&gl, Interpolation::Linear, Interpolation::Linear, Some(Interpolation::Linear),
- Wrapping::ClampToEdge, Wrapping::ClampToEdge, include_bytes!("../assets/textures/test_texture.jpg")).unwrap();
+ Wrapping::ClampToEdge, Wrapping::ClampToEdge, loaded.get("examples/assets/textures/test_texture.jpg").unwrap()).unwrap();
let box_mesh = TexturedMesh::new(&gl, &box_mesh.indices_buffer(), &box_mesh.positions_buffer_f32(), &box_mesh.normals_buffer_f32(), &[], texture).unwrap();
let texture3d = TextureCubeMap::new_from_bytes(&gl, Interpolation::Linear, Interpolation::Linear, None, Wrapping::ClampToEdge, Wrapping::ClampToEdge, Wrapping::ClampToEdge,
@@ -29,7 +33,7 @@ fn main() {
let penguin_texture = texture::Texture2D::new_from_bytes(&gl, Interpolation::Linear, Interpolation::Linear, Some(Interpolation::Linear),
Wrapping::ClampToEdge, Wrapping::ClampToEdge, include_bytes!("../assets/textures/penguin.png")).unwrap();
- let penguin = TexturedMesh::from_file(&gl, "examples/assets/models/penguin.3d", penguin_texture);
+ let penguin = TexturedMesh::from_cpu_mesh(&gl, &ThreeD::parse(loaded.get("examples/assets/models/penguin.3d").unwrap()).unwrap(), penguin_texture).unwrap();
let ambient_light = AmbientLight::new(&gl, 0.4, &vec3(1.0, 1.0, 1.0)).unwrap();
let directional_light = DirectionalLight::new(&gl, 1.0, &vec3(1.0, 1.0, 1.0), &vec3(0.0, -1.0, -1.0)).unwrap();
@@ -69,7 +73,7 @@ fn main() {
let mut transformation = Mat4::identity();
box_mesh.render(&transformation, &camera);
transformation = Mat4::from_translation(vec3(0.0, 1.0, 0.0));
- penguin.borrow_mut().render(&transformation, &camera);
+ penguin.render(&transformation, &camera);
}).unwrap();
Screen::write(&gl, 0, 0, width, height, Some(&vec4(0.8, 0.0, 0.0, 1.0)), None, &|| {
@@ -83,4 +87,7 @@ fn main() {
std::process::exit(1);
}
}).unwrap();
+ });
+
+
}
\ No newline at end of file
