From 2f3eab4d1e92ae3e79df34c89c999b64166ed04c Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Thu, 9 Feb 2023 04:11:15 +0100 Subject: [PATCH] why doesnt it work --- kubi/shaders/gui/progressbar.vert | 17 ++++++++++++---- kubi/src/gui.rs | 32 +++++++++---------------------- kubi/src/gui/progressbar.rs | 13 ++++++------- kubi/src/transform.rs | 6 +++++- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/kubi/shaders/gui/progressbar.vert b/kubi/shaders/gui/progressbar.vert index d57292c..8ae28dd 100644 --- a/kubi/shaders/gui/progressbar.vert +++ b/kubi/shaders/gui/progressbar.vert @@ -2,11 +2,20 @@ in vec2 position; out vec2 uv; -uniform vec2 ui_view; -uniform vec2 element_position; -uniform vec2 element_size; +uniform mat4 ui_view; +uniform mat3 transform; + +//not sure if mat4(i) does the same thing +mat4 extend(mat3 i) { + mat4 o; + o[0] = vec4(i[0].xyz, 0); + o[1] = vec4(i[1].xyz, 0); + o[2] = vec4(i[2].xyz, 0); + o[3] = vec4(0, 0, 0, 1); + return o; +} void main() { uv = position; - gl_Position = vec4(ui_view * (element_position + (position * element_size)), 0.0, 1.0); + gl_Position = ui_view * extend(transform) * vec4(position, 0., 1.); } diff --git a/kubi/src/gui.rs b/kubi/src/gui.rs index ebdb0c1..cbc5017 100644 --- a/kubi/src/gui.rs +++ b/kubi/src/gui.rs @@ -1,6 +1,6 @@ use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, AllStoragesViewMut}; -use glam::{Vec2, Vec4, vec2}; -use crate::color::color_hex; +use glam::{Vec2, Vec4, Mat3, vec2, Mat4}; +use crate::{color::color_hex, transform::Transform2d}; pub mod text_widget; pub mod progressbar; @@ -9,26 +9,11 @@ use progressbar::{render_progressbars, ProgressbarComponent}; //TODO compute gui scale on window resize #[derive(Unique, Clone, Copy, Debug)] -pub struct GuiViewScale(pub Vec2); +pub struct GuiView(pub Mat4); #[derive(Component, Clone, Copy, Debug, Default)] pub struct GuiComponent; -#[derive(Component, Clone, Copy, Debug)] -#[track(All)] -pub struct GuiTransform { - pub position: Vec2, - pub scale: Vec2, -} -impl Default for GuiTransform { - fn default() -> Self { - Self { - position: Vec2::ZERO, - scale: Vec2::ONE, - } - } -} - #[derive(Component, Clone, Copy, Debug)] pub struct PrimaryColor(pub Vec4); impl Default for PrimaryColor { @@ -54,7 +39,7 @@ pub fn render_gui() -> Workload { pub fn init_gui( storages: AllStoragesView, ) { - storages.add_unique(GuiViewScale(Vec2::ONE)); + storages.add_unique(GuiView(Mat4::orthographic_rh_gl(0.0, 1.0, 1.0, 0.0, 0.0, 1.0))); } pub fn gui_testing( @@ -62,10 +47,11 @@ pub fn gui_testing( ) { storages.add_entity(( GuiComponent, - GuiTransform { - position: Vec2::ZERO, - scale: vec2(1.0, 0.05), - }, + Transform2d(Mat3::from_scale_angle_translation( + vec2(0.25, 0.05), + 0., + vec2(0.5, 0.) + )), ProgressbarComponent { progress: 0.5 }, diff --git a/kubi/src/gui/progressbar.rs b/kubi/src/gui/progressbar.rs index 847c584..3e848c9 100644 --- a/kubi/src/gui/progressbar.rs +++ b/kubi/src/gui/progressbar.rs @@ -5,9 +5,9 @@ use crate::{ rendering::{ RenderTarget, primitives::rect::RectPrimitive - }, + }, transform::Transform2d, }; -use super::{GuiComponent, GuiTransform, PrimaryColor, SecondaryColor, GuiViewScale}; +use super::{GuiComponent, PrimaryColor, SecondaryColor, GuiView}; #[derive(Component, Debug, Clone, Copy, Default)] pub struct ProgressbarComponent { @@ -18,9 +18,9 @@ pub fn render_progressbars( mut target: NonSendSync>, rect: NonSendSync>, program: NonSendSync>, - view: UniqueView, + view: UniqueView, components: View, - transforms: View, + transforms: View, progressbars: View, primary: View, secondary: View, @@ -34,9 +34,8 @@ pub fn render_progressbars( &rect.1, &program.0, &uniform! { - element_position: transform.position.to_array(), - element_size: transform.scale.to_array(), - ui_view: view.0.to_array(), + transform: transform.0.to_cols_array_2d(), + ui_view: view.0.to_cols_array_2d(), progress: progress.progress, color: pri.unwrap_or_default().0.to_array(), bg_color: sec.unwrap_or_default().0.to_array(), diff --git a/kubi/src/transform.rs b/kubi/src/transform.rs index 643603e..6d38bfe 100644 --- a/kubi/src/transform.rs +++ b/kubi/src/transform.rs @@ -1,6 +1,10 @@ use shipyard::Component; -use glam::{Mat4, Vec2}; +use glam::{Mat4, Mat3}; #[derive(Component, Clone, Copy, Debug, Default)] #[track(All)] pub struct Transform(pub Mat4); + +#[derive(Component, Clone, Copy, Debug, Default)] +#[track(All)] +pub struct Transform2d(pub Mat3);