wip
This commit is contained in:
parent
999e86224a
commit
a8357a8876
3 changed files with 12 additions and 17 deletions
|
|
@ -17,7 +17,7 @@ fn main() {
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
material::update_material_time,
|
material::update_material_time,
|
||||||
systems::resize_fullscreen_quad,
|
systems::screen_resized,
|
||||||
systems::exit_app.run_if(input_just_pressed(KeyCode::Escape)),
|
systems::exit_app.run_if(input_just_pressed(KeyCode::Escape)),
|
||||||
systems::toggle_fullscreen.run_if(input_just_pressed(KeyCode::F11)),
|
systems::toggle_fullscreen.run_if(input_just_pressed(KeyCode::F11)),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use bevy::{
|
||||||
|
|
||||||
const DEFAULT_SHADER_PATH: &str = "shaders/default.wgsl";
|
const DEFAULT_SHADER_PATH: &str = "shaders/default.wgsl";
|
||||||
|
|
||||||
// This is the struct that will be passed to your shader
|
|
||||||
#[derive(Asset, TypePath, AsBindGroup, Clone)]
|
#[derive(Asset, TypePath, AsBindGroup, Clone)]
|
||||||
pub struct CustomMaterial {
|
pub struct CustomMaterial {
|
||||||
#[uniform(0)]
|
#[uniform(0)]
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,19 @@
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
window::{PrimaryWindow, WindowMode},
|
window::{PrimaryWindow, WindowMode, WindowResized},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::material::CustomMaterial;
|
use crate::material::CustomMaterial;
|
||||||
|
|
||||||
/// Marker component for the fullscreen quad so we can update it on window resize
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct FullscreenQuad;
|
pub struct FullscreenQuad;
|
||||||
|
|
||||||
/// set up a simple 2D-screen-like surface
|
|
||||||
pub fn setup(
|
pub fn setup(
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<CustomMaterial>>,
|
mut materials: ResMut<Assets<CustomMaterial>>,
|
||||||
mut primary_window: Single<&mut Window, With<PrimaryWindow>>,
|
primary_window: Single<&Window, With<PrimaryWindow>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
primary_window.decorations = false;
|
|
||||||
|
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
|
|
||||||
// quad that fills the whole window
|
// quad that fills the whole window
|
||||||
|
|
@ -39,16 +35,16 @@ pub fn setup(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update fullscreen quad transforms when the primary window is resized.
|
pub fn screen_resized(
|
||||||
pub fn resize_fullscreen_quad(
|
mut events: EventReader<WindowResized>,
|
||||||
primary_window: Single<&Window, With<PrimaryWindow>>,
|
shader_data: Single<(&mut Transform, &MeshMaterial2d<CustomMaterial>), With<FullscreenQuad>>,
|
||||||
mut transform: Single<&mut Transform, With<FullscreenQuad>>,
|
mut materials: ResMut<Assets<CustomMaterial>>,
|
||||||
) {
|
) {
|
||||||
let size = Vec2::new(
|
let (mut transform, material) = shader_data.into_inner();
|
||||||
primary_window.resolution.width(),
|
if let Some(event) = events.read().last() {
|
||||||
primary_window.resolution.height(),
|
transform.scale = Vec3::new(event.width, event.height, 1.0);
|
||||||
);
|
materials.get_mut(&material.0).unwrap().resolution = Vec2::new(event.width, event.height);
|
||||||
transform.scale = Vec3::new(size.x, size.y, 1.0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit_app(mut exit: EventWriter<AppExit>) {
|
pub fn exit_app(mut exit: EventWriter<AppExit>) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue