vertex +normals
This commit is contained in:
+64
-5
@@ -2,16 +2,75 @@ use std::sync::Arc;
|
||||
use winit::event_loop::EventLoop;
|
||||
use winit::window::WindowBuilder;
|
||||
use wsg_lib::context::Context;
|
||||
use wsg_lib::material::Material;
|
||||
use wsg_lib::mesh::Mesh;
|
||||
use wsg_lib::pipeline_cache::PipelineCache;
|
||||
use wsg_lib::renderer::Renderer;
|
||||
|
||||
fn main() {
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap());
|
||||
|
||||
// Utilisation de pollster pour le bloc async
|
||||
// Initialisation contexte matériel (device, queue, surface) Utilisation de pollster pour le bloc async
|
||||
let context = pollster::block_on(Context::new(window.clone()));
|
||||
|
||||
match context {
|
||||
Ok(_) => println!("Succès : WGPU context initialisé !"),
|
||||
Err(e) => eprintln!("Erreur lors de l'initialisation : {:?}", e),
|
||||
}
|
||||
// Initialisation des briques de rendu
|
||||
let mut cache = PipelineCache::new();
|
||||
cache
|
||||
.register_shader("basic", "assets/shaders/basic.wgsl")
|
||||
.unwrap();
|
||||
let renderer = Renderer::new(&context, &cache);
|
||||
|
||||
// Creation d'un material (charge le basic shader via le cache)
|
||||
let material = Material::new(&context.device, context.config.format, "basic", &mut cache);
|
||||
// Creation d'un mesh
|
||||
// 1. Définition des sommets (avec position et couleur pour l'interpolation)
|
||||
let vertices = [
|
||||
Vertex {
|
||||
position: [-0.5, 0.5, 0.0],
|
||||
color: [1.0, 0.0, 0.0],
|
||||
}, // Haut-Gauche (Rouge)
|
||||
Vertex {
|
||||
position: [0.5, 0.5, 0.0],
|
||||
color: [0.0, 1.0, 0.0],
|
||||
}, // Haut-Droite (Vert)
|
||||
Vertex {
|
||||
position: [0.5, -0.5, 0.0],
|
||||
color: [0.0, 0.0, 1.0],
|
||||
}, // Bas-Droite (Bleu)
|
||||
Vertex {
|
||||
position: [-0.5, -0.5, 0.0],
|
||||
color: [1.0, 1.0, 1.0],
|
||||
}, // Bas-Gauche (Blanc)
|
||||
];
|
||||
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3];
|
||||
let mesh = Mesh::new(&context.device, &vertices, Some(&indices));
|
||||
|
||||
// Render loop
|
||||
event_loop
|
||||
.run(|event, elwt| {
|
||||
match event {
|
||||
winit::event::Event::AboutToWait => {
|
||||
window.request_redraw();
|
||||
}
|
||||
winit::event::Event::WindowEvent {
|
||||
event: winit::event::WindowEvent::RedrawRequested,
|
||||
..
|
||||
} => {
|
||||
// Acquisition de la cible de rendu
|
||||
let frame = context.surface.get_current_texture().unwrap();
|
||||
let view = frame
|
||||
.texture
|
||||
.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
// Orchestration du rendu
|
||||
renderer.render(&context.device, &context.queue, &view, &mesh, &material);
|
||||
|
||||
// Presentation de l'image
|
||||
frame.present();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user