diff --git a/Cargo.lock b/Cargo.lock index 3ea82a2..57a2405 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1071,6 +1071,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "pollster" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" + [[package]] name = "portable-atomic" version = "1.13.1" @@ -2298,6 +2304,15 @@ version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" +[[package]] +name = "wsg-examples" +version = "0.1.0" +dependencies = [ + "pollster", + "winit", + "wsg-lib", +] + [[package]] name = "wsg-lib" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 9c53186..4b27356 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,3 @@ [workspace] -members = ["lib"] -exclude = ["examples"] +members = ["lib", "examples"] resolver = "2" diff --git a/examples/main.rs b/examples/main.rs index 0185d93..cf3d3e1 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -11,6 +11,10 @@ use wsg_lib::renderer::Renderer; use wsg_lib::vertex::Vertex; fn main() { + println!( + "Répertoire courant : {:?}", + std::env::current_dir().unwrap() + ); let event_loop = EventLoop::new().unwrap(); let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); @@ -24,7 +28,9 @@ fn main() { // 2. Initialisation du Renderer (Il récupère tout ce dont il a besoin) let mut cache = PipelineCache::new(); - cache.register_shader("basic", conf::BASIC_SHADER).unwrap(); + cache + .register_shader("basic", conf::BASIC_SHADER_PATH) + .unwrap(); let renderer = Renderer::new(&context, format); @@ -32,7 +38,33 @@ fn main() { let material = Material::new(renderer.device(), renderer.format(), "basic", &mut cache); // Mesh : On utilise le device du renderer - let vertices = [ /* ... tes sommets ... */ ]; + let vertices = [ + // Position (x,y,z) | Normale (x,y,z) | UV (u,v) | Couleur (r,g,b,a) + Vertex { + position: [-0.5, 0.5, 0.0], + normal: [0.0, 0.0, 1.0], + uv: [0.0, 0.0], + color: [1.0, 0.0, 0.0, 1.0], + }, // Haut-Gauche (Rouge) + Vertex { + position: [0.5, 0.5, 0.0], + normal: [0.0, 0.0, 1.0], + uv: [1.0, 0.0], + color: [0.0, 1.0, 0.0, 1.0], + }, // Haut-Droite (Vert) + Vertex { + position: [0.5, -0.5, 0.0], + normal: [0.0, 0.0, 1.0], + uv: [1.0, 1.0], + color: [0.0, 0.0, 1.0, 1.0], + }, // Bas-Droite (Bleu) + Vertex { + position: [-0.5, -0.5, 0.0], + normal: [0.0, 0.0, 1.0], + uv: [0.0, 1.0], + color: [1.0, 1.0, 0.0, 1.0], + }, // Bas-Gauche (Jaune) + ]; let indices: [u16; 6] = [0, 1, 2, 0, 2, 3]; let mesh = Mesh::new(renderer.device(), &vertices, Some(&indices)); @@ -55,6 +87,12 @@ fn main() { renderer.present(frame); } } + winit::event::Event::WindowEvent { + event: winit::event::WindowEvent::CloseRequested, + .. + } => { + elwt.exit(); // C'est ici que tu demandes à la boucle de s'arrêter + } _ => (), } }) diff --git a/lib/pipeline_cache.rs b/lib/pipeline_cache.rs index bab006e..13a8207 100644 --- a/lib/pipeline_cache.rs +++ b/lib/pipeline_cache.rs @@ -57,7 +57,7 @@ impl PipelineCache { if self.shader_paths.remove(id).is_none() { return Err(format!("ID '{}' does not exist.", id)); } - // Remove cached pipeline so GPU memory is freed (wgpu drops it automatically) + // Remove cached pipeline so GPU memory is freed (wgpu drops it automatically) Ok(id.to_string()) }