resize
This commit is contained in:
parent
abff3f5434
commit
68763ea15c
1 changed files with 18 additions and 0 deletions
18
src/main.rs
18
src/main.rs
|
|
@ -17,6 +17,7 @@ fn main() {
|
||||||
Material2dPlugin::<CustomMaterial>::default(),
|
Material2dPlugin::<CustomMaterial>::default(),
|
||||||
))
|
))
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
|
.add_systems(Update, resize_fullscreen_quad)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,9 +41,26 @@ fn setup(
|
||||||
Mesh2d(meshes.add(Rectangle::default())),
|
Mesh2d(meshes.add(Rectangle::default())),
|
||||||
MeshMaterial2d(materials.add(CustomMaterial {})),
|
MeshMaterial2d(materials.add(CustomMaterial {})),
|
||||||
Transform::from_scale(Vec3::new(size.x, size.y, 1.0)),
|
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<PrimaryWindow>>,
|
||||||
|
mut transform: Single<&mut Transform, With<FullscreenQuad>>,
|
||||||
|
) {
|
||||||
|
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
|
// This is the struct that will be passed to your shader
|
||||||
#[derive(Asset, TypePath, AsBindGroup, Clone)]
|
#[derive(Asset, TypePath, AsBindGroup, Clone)]
|
||||||
struct CustomMaterial {}
|
struct CustomMaterial {}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue