mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
why doesnt it work
This commit is contained in:
parent
da4a686100
commit
e75693926a
|
@ -2,11 +2,20 @@
|
||||||
|
|
||||||
in vec2 position;
|
in vec2 position;
|
||||||
out vec2 uv;
|
out vec2 uv;
|
||||||
uniform vec2 ui_view;
|
uniform mat4 ui_view;
|
||||||
uniform vec2 element_position;
|
uniform mat3 transform;
|
||||||
uniform vec2 element_size;
|
|
||||||
|
//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() {
|
void main() {
|
||||||
uv = position;
|
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.);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, AllStoragesViewMut};
|
use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, AllStoragesViewMut};
|
||||||
use glam::{Vec2, Vec4, vec2};
|
use glam::{Vec2, Vec4, Mat3, vec2, Mat4};
|
||||||
use crate::color::color_hex;
|
use crate::{color::color_hex, transform::Transform2d};
|
||||||
|
|
||||||
pub mod text_widget;
|
pub mod text_widget;
|
||||||
pub mod progressbar;
|
pub mod progressbar;
|
||||||
|
@ -9,26 +9,11 @@ use progressbar::{render_progressbars, ProgressbarComponent};
|
||||||
|
|
||||||
//TODO compute gui scale on window resize
|
//TODO compute gui scale on window resize
|
||||||
#[derive(Unique, Clone, Copy, Debug)]
|
#[derive(Unique, Clone, Copy, Debug)]
|
||||||
pub struct GuiViewScale(pub Vec2);
|
pub struct GuiView(pub Mat4);
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, Debug, Default)]
|
#[derive(Component, Clone, Copy, Debug, Default)]
|
||||||
pub struct GuiComponent;
|
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)]
|
#[derive(Component, Clone, Copy, Debug)]
|
||||||
pub struct PrimaryColor(pub Vec4);
|
pub struct PrimaryColor(pub Vec4);
|
||||||
impl Default for PrimaryColor {
|
impl Default for PrimaryColor {
|
||||||
|
@ -54,7 +39,7 @@ pub fn render_gui() -> Workload {
|
||||||
pub fn init_gui(
|
pub fn init_gui(
|
||||||
storages: AllStoragesView,
|
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(
|
pub fn gui_testing(
|
||||||
|
@ -62,10 +47,11 @@ pub fn gui_testing(
|
||||||
) {
|
) {
|
||||||
storages.add_entity((
|
storages.add_entity((
|
||||||
GuiComponent,
|
GuiComponent,
|
||||||
GuiTransform {
|
Transform2d(Mat3::from_scale_angle_translation(
|
||||||
position: Vec2::ZERO,
|
vec2(0.25, 0.05),
|
||||||
scale: vec2(1.0, 0.05),
|
0.,
|
||||||
},
|
vec2(0.5, 0.)
|
||||||
|
)),
|
||||||
ProgressbarComponent {
|
ProgressbarComponent {
|
||||||
progress: 0.5
|
progress: 0.5
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,9 +5,9 @@ use crate::{
|
||||||
rendering::{
|
rendering::{
|
||||||
RenderTarget,
|
RenderTarget,
|
||||||
primitives::rect::RectPrimitive
|
primitives::rect::RectPrimitive
|
||||||
},
|
}, transform::Transform2d,
|
||||||
};
|
};
|
||||||
use super::{GuiComponent, GuiTransform, PrimaryColor, SecondaryColor, GuiViewScale};
|
use super::{GuiComponent, PrimaryColor, SecondaryColor, GuiView};
|
||||||
|
|
||||||
#[derive(Component, Debug, Clone, Copy, Default)]
|
#[derive(Component, Debug, Clone, Copy, Default)]
|
||||||
pub struct ProgressbarComponent {
|
pub struct ProgressbarComponent {
|
||||||
|
@ -18,9 +18,9 @@ pub fn render_progressbars(
|
||||||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||||
rect: NonSendSync<UniqueView<RectPrimitive>>,
|
rect: NonSendSync<UniqueView<RectPrimitive>>,
|
||||||
program: NonSendSync<UniqueView<ProgressbarShaderPrefab>>,
|
program: NonSendSync<UniqueView<ProgressbarShaderPrefab>>,
|
||||||
view: UniqueView<GuiViewScale>,
|
view: UniqueView<GuiView>,
|
||||||
components: View<GuiComponent>,
|
components: View<GuiComponent>,
|
||||||
transforms: View<GuiTransform>,
|
transforms: View<Transform2d>,
|
||||||
progressbars: View<ProgressbarComponent>,
|
progressbars: View<ProgressbarComponent>,
|
||||||
primary: View<PrimaryColor>,
|
primary: View<PrimaryColor>,
|
||||||
secondary: View<SecondaryColor>,
|
secondary: View<SecondaryColor>,
|
||||||
|
@ -34,9 +34,8 @@ pub fn render_progressbars(
|
||||||
&rect.1,
|
&rect.1,
|
||||||
&program.0,
|
&program.0,
|
||||||
&uniform! {
|
&uniform! {
|
||||||
element_position: transform.position.to_array(),
|
transform: transform.0.to_cols_array_2d(),
|
||||||
element_size: transform.scale.to_array(),
|
ui_view: view.0.to_cols_array_2d(),
|
||||||
ui_view: view.0.to_array(),
|
|
||||||
progress: progress.progress,
|
progress: progress.progress,
|
||||||
color: pri.unwrap_or_default().0.to_array(),
|
color: pri.unwrap_or_default().0.to_array(),
|
||||||
bg_color: sec.unwrap_or_default().0.to_array(),
|
bg_color: sec.unwrap_or_default().0.to_array(),
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
use shipyard::Component;
|
use shipyard::Component;
|
||||||
use glam::{Mat4, Vec2};
|
use glam::{Mat4, Mat3};
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, Debug, Default)]
|
#[derive(Component, Clone, Copy, Debug, Default)]
|
||||||
#[track(All)]
|
#[track(All)]
|
||||||
pub struct Transform(pub Mat4);
|
pub struct Transform(pub Mat4);
|
||||||
|
|
||||||
|
#[derive(Component, Clone, Copy, Debug, Default)]
|
||||||
|
#[track(All)]
|
||||||
|
pub struct Transform2d(pub Mat3);
|
||||||
|
|
Loading…
Reference in a new issue