examples: fix simple.rs to compile as the 15-line declarative model

- Replace the broken App::new() (which does not exist) with AppBuilder.
- Strip it down to the PLAN's ~15-line target: no explicit winit/wgpu,
  AppHandler render() left empty (scene rendering still on the roadmap).
- Verified: builds, opens a black window and runs the update->render->present
  loop until closed.
- Update README/PLAN wording now that the simple example compiles (it still
  does not draw a scene).
This commit is contained in:
Jérôme Bousquié
2026-09-14 15:42:30 +02:00
parent f6c0851d4f
commit 7cabda710d
3 changed files with 17 additions and 57 deletions
+11 -51
View File
@@ -1,59 +1,19 @@
use wsg_lib::resources::{Material, Mesh, Vertex};
use wsg_lib::utils;
//! Workflow déclaratif minimal (~15 lignes), sans manipulation WGPU explicite.
//! `AppBuilder` ouvre la fenêtre, construit le `Context`/`Renderer` et fait tourner la boucle
//! update → render → present. Le rendu automatisé de la scène n'est pas encore en place
//! (README, Roadmap étape 1) : `render()` est donc vide pour l'instant.
use wsg_lib::app::AppBuilder;
use wsg_lib::utils::WsgError;
use wsg_lib::{App, AppHandler};
// 1. On définit notre "Jeu" qui implémente le comportement
struct MonQuad {
mesh: Mesh,
material: Material,
}
struct MonQuad;
impl AppHandler for MonQuad {
fn render(&mut self, app: &mut App) {}
fn render(&mut self, _app: &mut App) {}
}
#[pollster::main]
async fn main() -> Result<(), wsg_lib::utils::WsgError> {
// 2. Initialisation via le Builder
let mut app = App::new().await?;
// 3. Setup des ressources (déclaration)
app.cache
.register_shader("basic", utils::BASIC_SHADER_PATH)
.unwrap();
let vertices: [Vertex; 4] = [
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],
},
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],
},
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],
},
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],
},
];
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3];
let mesh = Mesh::new(app.context.device(), &vertices, Some(&indices));
let material = Material::new(app.renderer.format(), "basic", &mut app.cache);
// 4. Lancement de la boucle (la magie opère ici)
let handler = MonQuad { mesh, material };
app.run(handler)
async fn main() -> Result<(), WsgError> {
let app = AppBuilder::new().title("WSG Simple").build().await?;
app.run(MonQuad)
}