diff --git a/examples/tetris/main.rs b/examples/tetris/main.rs index c1b3dc3..191c264 100644 --- a/examples/tetris/main.rs +++ b/examples/tetris/main.rs @@ -1,34 +1,20 @@ +use scion::game_layer::{GameLayer, GameLayerController, SimpleGameLayer}; +use scion::legion::{Resources, system, World}; +use scion::rendering::bidimensional::{Camera2D, Material2D, Position2D, Transform2D}; +use scion::rendering::bidimensional::components::Square; use scion::Scion; -use scion::legion::{system, World, Resources}; -use scion::game_layer::{SimpleGameLayer, GameLayer, GameLayerController}; #[system] -fn test(){ +fn test() { log::info!("Hello all"); } #[derive(Default)] -struct LayerA{ - tmp: usize -} +struct LayerA; -impl SimpleGameLayer for LayerA{ - fn update(&mut self, _world: &mut World, resource: &mut Resources) { - log::info!("HeullohA...{}", self.tmp); - self.tmp += 1; - if self.tmp >= 301 { - resource.get_mut::().unwrap().pop_layer(); - resource.get_mut::().unwrap().push_layer(GameLayer::strong::()); - } - } -} - -#[derive(Default)] -struct LayerB; +impl SimpleGameLayer for LayerA { + fn on_start(&mut self, world: &mut World, resource: &mut Resources) { -impl SimpleGameLayer for LayerB{ - fn update(&mut self, _world: &mut World, _resource: &mut Resources) { - log::info!("HeullohB..."); } } diff --git a/src/rendering/bidimensional/components/square.rs b/src/rendering/bidimensional/components/square.rs index ad89723..362534c 100644 --- a/src/rendering/bidimensional/components/square.rs +++ b/src/rendering/bidimensional/components/square.rs @@ -1,8 +1,6 @@ use std::ops::Range; -use wgpu::{ - util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor, -}; +use wgpu::{util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor, BlendFactor, BlendOperation}; use crate::rendering::bidimensional::{ gl_representations::TexturedGlVertex, scion2d::Renderable2D, transform::Position2D, @@ -98,8 +96,16 @@ impl Renderable2D for Square { entry_point: "main", targets: &[wgpu::ColorTargetState { format: sc_desc.format, - alpha_blend: wgpu::BlendState::REPLACE, - color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState { + src_factor: BlendFactor::One, + dst_factor: BlendFactor::One, + operation: BlendOperation::Add, + }, + color_blend: wgpu::BlendState { + src_factor: BlendFactor::SrcAlpha, + dst_factor: BlendFactor::OneMinusSrcAlpha, + operation: BlendOperation::Add, + }, write_mask: wgpu::ColorWrite::ALL, }], }), diff --git a/src/rendering/bidimensional/components/triangle.rs b/src/rendering/bidimensional/components/triangle.rs index 2b7b879..65ef53e 100644 --- a/src/rendering/bidimensional/components/triangle.rs +++ b/src/rendering/bidimensional/components/triangle.rs @@ -1,8 +1,6 @@ use std::ops::Range; -use wgpu::{ - util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor, -}; +use wgpu::{util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor, BlendFactor, BlendOperation}; use crate::rendering::bidimensional::{ gl_representations::TexturedGlVertex, scion2d::Renderable2D, transform::Position2D, @@ -84,8 +82,16 @@ impl Renderable2D for Triangle { entry_point: "main", targets: &[wgpu::ColorTargetState { format: sc_desc.format, - alpha_blend: wgpu::BlendState::REPLACE, - color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState { + src_factor: BlendFactor::One, + dst_factor: BlendFactor::One, + operation: BlendOperation::Add, + }, + color_blend: wgpu::BlendState { + src_factor: BlendFactor::SrcAlpha, + dst_factor: BlendFactor::OneMinusSrcAlpha, + operation: BlendOperation::Add, + }, write_mask: wgpu::ColorWrite::ALL, }], }), diff --git a/src/rendering/bidimensional/scion2d.rs b/src/rendering/bidimensional/scion2d.rs index e595ca6..9a60e60 100644 --- a/src/rendering/bidimensional/scion2d.rs +++ b/src/rendering/bidimensional/scion2d.rs @@ -216,7 +216,7 @@ fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAtta resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { - r: 0., + r: 1., g: 0., b: 0., a: 1.0,