From 0c25bfa5ae6ca541162f50b0a9250944e8213b35 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sat, 28 Jan 2023 21:28:25 +0100 Subject: [PATCH] selection kinda works --- src/rendering/selection_box.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/rendering/selection_box.rs b/src/rendering/selection_box.rs index a359163..88ac6c5 100644 --- a/src/rendering/selection_box.rs +++ b/src/rendering/selection_box.rs @@ -1,5 +1,14 @@ use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView}; -use glium::{Surface, implement_vertex, IndexBuffer, index::PrimitiveType, VertexBuffer, uniform, DrawParameters, Blend, BackfaceCullingMode}; +use glium::{ + Surface, + implement_vertex, + IndexBuffer, + index::PrimitiveType, + VertexBuffer, uniform, + DrawParameters, + BackfaceCullingMode, + PolygonMode, Blend, BlendingFunction, LinearBlendingFactor, Depth, DepthTest +}; use crate::{ world::raycast::LookingAtBlock, camera::Camera, prefabs::SelBoxShaderPrefab @@ -62,14 +71,29 @@ pub fn render_selection_box( &index, &program.0, &uniform! { - color: [0., 0., 0., 0.5_f32], + color: [0., 0., 0., 1.], u_position: lookat.block_position.as_vec3().to_array(), perspective: camera.perspective_matrix.to_cols_array_2d(), view: camera.view_matrix.to_cols_array_2d(), }, &DrawParameters { - blend: Blend::alpha_blending(), backface_culling: BackfaceCullingMode::CullClockwise, + blend: Blend { + //for some reason only constant alpha works??? + color: BlendingFunction::Addition { + source: LinearBlendingFactor::ConstantAlpha, + destination: LinearBlendingFactor::OneMinusConstantAlpha, + }, + alpha: BlendingFunction::Addition { + source: LinearBlendingFactor::ConstantAlpha, + destination: LinearBlendingFactor::OneMinusConstantAlpha + }, + constant_value: (0.0, 0.0, 0.0, 0.5) + }, + depth: Depth { + test: DepthTest::IfLessOrEqual, //this may be unreliable! + ..Default::default() + }, ..Default::default() } ).unwrap();