diff --git a/shaders/selection_box.frag b/shaders/selection_box.frag new file mode 100644 index 0000000..9b2ac94 --- /dev/null +++ b/shaders/selection_box.frag @@ -0,0 +1,8 @@ +#version 150 core + +out vec4 color; +uniform vec4 u_color; + +void main() { + color = u_color; +} diff --git a/shaders/selection_box.vert b/shaders/selection_box.vert new file mode 100644 index 0000000..7243a1f --- /dev/null +++ b/shaders/selection_box.vert @@ -0,0 +1,10 @@ +#version 150 core + +in vec3 position; +uniform vec3 u_position; +uniform mat4 perspective; +uniform mat4 view; + +void main() { + gl_Position = perspective * view * vec4(position + u_position, 1.); +} diff --git a/src/prefabs.rs b/src/prefabs.rs index fc1e075..793966e 100644 --- a/src/prefabs.rs +++ b/src/prefabs.rs @@ -56,6 +56,9 @@ pub struct BlockTexturesPrefab(pub SrgbTexture2dArray); #[derive(Unique)] pub struct ChunkShaderPrefab(pub Program); +#[derive(Unique)] +pub struct SelBoxShaderPrefab(pub Program); + pub fn load_prefabs( storages: AllStoragesView, renderer: NonSendSync> @@ -74,4 +77,11 @@ pub fn load_prefabs( &renderer.display ) )); + storages.add_unique_non_send_sync(SelBoxShaderPrefab( + include_shader_prefab!( + "../shaders/selection_box.vert", + "../shaders/selection_box.frag", + &renderer.display + ) + )); } diff --git a/src/rendering.rs b/src/rendering.rs index 7a42932..9389e76 100644 --- a/src/rendering.rs +++ b/src/rendering.rs @@ -9,6 +9,7 @@ use glium::{ }; use glam::Vec3; +pub mod primitives; pub mod world; pub mod selection_box; diff --git a/src/rendering/primitives.rs b/src/rendering/primitives.rs new file mode 100644 index 0000000..998ad16 --- /dev/null +++ b/src/rendering/primitives.rs @@ -0,0 +1,32 @@ +const CUBE_VERTICES: &[f32] = &[ + // front + -1.0, -1.0, 1.0, + 1.0, -1.0, 1.0, + 1.0, 1.0, 1.0, + -1.0, 1.0, 1.0, + // back + -1.0, -1.0, -1.0, + 1.0, -1.0, -1.0, + 1.0, 1.0, -1.0, + -1.0, 1.0, -1.0 +]; +const CUBE_INDICES: &[u16] = &[ + // front + 0, 1, 2, + 2, 3, 0, + // right + 1, 5, 6, + 6, 2, 1, + // back + 7, 6, 5, + 5, 4, 7, + // left + 4, 0, 3, + 3, 7, 4, + // bottom + 4, 5, 1, + 1, 0, 4, + // top + 3, 2, 6, + 6, 7, 3 +]; diff --git a/src/rendering/selection_box.rs b/src/rendering/selection_box.rs index 7d757f8..6301a0d 100644 --- a/src/rendering/selection_box.rs +++ b/src/rendering/selection_box.rs @@ -1,12 +1,16 @@ use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut}; -use glium::Surface; +use glium::{Surface, implement_vertex}; use crate::{ world::raycast::LookingAtBlock, camera::Camera }; use super::RenderTarget; -const CUBE_VERTICES: &[f32] = &[0.0]; +#[derive(Clone, Copy)] +pub struct SelBoxVertex { + pub position: [f32; 3], +} +implement_vertex!(SelBoxVertex, position); //wip pub fn render_selection_box(