From f4911acd7458c667f068551613aa93604f6a8630 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Sun, 26 Nov 2023 23:03:29 +0000 Subject: [PATCH] chore: try to fix an error...needs fixing --- flake.lock | 98 ------------------------- flake.nix | 28 +++++-- src/main.rs | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 227 insertions(+), 107 deletions(-) delete mode 100644 flake.lock diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 1572263..0000000 --- a/flake.lock +++ /dev/null @@ -1,98 +0,0 @@ -{ - "nodes": { - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1697178193, - "narHash": "sha256-LBDLUWlwSDPMA1Ui9wC9YcQEnJL0UP627RoUmtz4TTo=", - "owner": "nix-community", - "repo": "fenix", - "rev": "ff6c27356cbde594e598e388a32d79ef79cbe1b1", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1697009197, - "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "root": { - "inputs": { - "fenix": "fenix", - "nixpkgs": "nixpkgs", - "utils": "utils" - } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1697098808, - "narHash": "sha256-OfatUxSwuzYd17IDy9eNOedwioq0dX6mOuiTghKol3s=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "84e1d273439413ab4ca1718db0b574dffba443ce", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix index f8b8c7c..ca7e01d 100644 --- a/flake.nix +++ b/flake.nix @@ -1,27 +1,30 @@ { - description = "Rust development template using fenix"; + description = "Rust development environment for Aspiration using fenix"; inputs = { fenix = { url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixpkgs.follows = "nixpkgs-unstable"; }; utils.url = "github:numtide/flake-utils"; + nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; + nixgl.url = "github:guibou/nixGL"; }; outputs = { self, - nixpkgs, + nixpkgs-unstable, utils, fenix, + nixgl, ... }: utils.lib.eachDefaultSystem ( system: let - pkgs = import nixpkgs { + pkgs = import nixpkgs-unstable { inherit system; - overlays = [fenix.overlays.default]; + overlays = [fenix.overlays.default nixgl.overlay]; }; toolchain = pkgs.fenix.complete; in rec @@ -33,7 +36,7 @@ inherit (toolchain) cargo rustc; }) .buildRustPackage { - pname = "template"; + pname = "aspiration"; version = "0.1.0"; src = ./.; cargoLock.lockFile = ./Cargo.lock; @@ -46,7 +49,14 @@ apps.default = utils.lib.mkApp {drv = packages.default;}; # Used by `nix develop` - devShells.default = pkgs.mkShell { + devShells.default = pkgs.mkShell rec { + shellHook = ''export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [ + pkgs.vulkan-loader + pkgs.xorg.libX11 + pkgs.xorg.libXcursor + pkgs.xorg.libXi + pkgs.xorg.libXrandr + ]}"''; # Use nightly cargo & rustc provided by fenix. Add for packages for the dev shell here buildInputs = with pkgs; [ (with toolchain; [ @@ -55,11 +65,13 @@ xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature libxkbcommon wayland # To use the wayland feature + udev alsa-lib vulkan-loader + pkgs.nixgl.nixVulkanIntel + mold clang pkg-config ]; - # Specify the rust-src path (many editors rely on this) RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library"; }; diff --git a/src/main.rs b/src/main.rs index e7a11a9..a8037a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,209 @@ +//! Illustrates bloom post-processing in 2d. + +use bevy::{ + core_pipeline::{ + bloom::{BloomCompositeMode, BloomSettings}, + tonemapping::Tonemapping, + }, + prelude::*, + sprite::MaterialMesh2dBundle, +}; + fn main() { - println!("Hello, world!"); + App::new() + .add_plugins(DefaultPlugins) + .add_systems(Startup, setup) + .add_systems(Update, update_bloom_settings) + .run(); } + +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, + asset_server: Res, +) { + commands.spawn(( + Camera2dBundle { + camera: Camera { + hdr: true, // 1. HDR is required for bloom + ..default() + }, + tonemapping: Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended + ..default() + }, + BloomSettings::default(), // 3. Enable bloom for the camera + )); + + // Sprite + commands.spawn(SpriteBundle { + texture: asset_server.load("branding/bevy_bird_dark.png"), + sprite: Sprite { + color: Color::rgb(5.0, 5.0, 5.0), // 4. Put something bright in a dark environment to see the effect + custom_size: Some(Vec2::splat(160.0)), + ..default() + }, + ..default() + }); + + // Circle mesh + commands.spawn(MaterialMesh2dBundle { + mesh: meshes.add(shape::Circle::new(100.).into()).into(), + // 4. Put something bright in a dark environment to see the effect + material: materials.add(ColorMaterial::from(Color::rgb(7.5, 0.0, 7.5))), + transform: Transform::from_translation(Vec3::new(-200., 0., 0.)), + ..default() + }); + + // Hexagon mesh + commands.spawn(MaterialMesh2dBundle { + mesh: meshes + .add(shape::RegularPolygon::new(100., 6).into()) + .into(), + // 4. Put something bright in a dark environment to see the effect + material: materials.add(ColorMaterial::from(Color::rgb(6.25, 9.4, 9.1))), + transform: Transform::from_translation(Vec3::new(200., 0., 0.)), + ..default() + }); + + // UI + commands.spawn( + TextBundle::from_section( + "", + TextStyle { + font_size: 18.0, + color: Color::WHITE, + ..default() + }, + ) + .with_style(Style { + position_type: PositionType::Absolute, + bottom: Val::Px(10.0), + left: Val::Px(10.0), + ..default() + }), + ); +} + +// ------------------------------------------------------------------------------------------------ + +fn update_bloom_settings( + mut camera: Query<(Entity, Option<&mut BloomSettings>), With>, + mut text: Query<&mut Text>, + mut commands: Commands, + keycode: Res>, + time: Res