diff --git a/src/main.rs b/src/main.rs index 9364d99..4b2a756 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ fn main() { Material2dPlugin::::default(), )) .add_systems(Startup, setup) + .add_systems(Update, resize_fullscreen_quad) .run(); } @@ -40,9 +41,26 @@ fn setup( Mesh2d(meshes.add(Rectangle::default())), MeshMaterial2d(materials.add(CustomMaterial {})), Transform::from_scale(Vec3::new(size.x, size.y, 1.0)), + FullscreenQuad, )); } +/// Marker component for the fullscreen quad so we can update it on window resize +#[derive(Component)] +struct FullscreenQuad; + +/// Update fullscreen quad transforms when the primary window is resized. +fn resize_fullscreen_quad( + primary_window: Single<&Window, With>, + mut transform: Single<&mut Transform, With>, +) { + let size = Vec2::new( + primary_window.resolution.width(), + primary_window.resolution.height(), + ); + transform.scale = Vec3::new(size.x, size.y, 1.0); +} + // This is the struct that will be passed to your shader #[derive(Asset, TypePath, AsBindGroup, Clone)] struct CustomMaterial {}