-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: addition to the rendering trait and banner
- Loading branch information
Showing
9 changed files
with
175 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# scion | ||
Scion is a minimalist, **easy** to use, game engine built on top of legion and miniquad. | ||
<img src="repo/banner.png" alt="Scion Engine" /> | ||
|
||
Scion is a minimalist, **easy** to use, modulable game engine built on top of legion and miniquad. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ pub use legion; | |
pub mod application; | ||
pub mod config; | ||
pub mod utils; | ||
pub mod renderer; | ||
pub mod renderer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pub mod renderer; | ||
pub mod triangle; | ||
|
||
#[repr(C)] | ||
pub struct Vec2 { | ||
x: f32, | ||
y: f32, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Vec4 { | ||
r: f32, | ||
g: f32, | ||
b: f32, | ||
a: f32, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Vertex { | ||
pos: Vec2, | ||
color: Vec4, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Uniforms { | ||
pub offset: (f32, f32), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::renderer::{ScionRenderer, Renderable2D}; | ||
use miniquad::Context; | ||
use legion::{Resources, World, Entity, IntoQuery}; | ||
use crate::renderer::bidimensional::triangle::Triangle; | ||
|
||
|
||
pub struct Scion2D; | ||
|
||
impl ScionRenderer for Scion2D { | ||
fn draw(&mut self, context: &mut Context, world: &mut World, _resource: &mut Resources) { | ||
let mut query_triangles = <(Entity, &Triangle)>::query(); | ||
query_triangles.for_each(world,|_triangle|{ | ||
Triangle::render(context) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use crate::renderer::Renderable2D; | ||
use miniquad::{Context, Buffer, BufferType, Bindings, Shader, Pipeline, BufferLayout, VertexAttribute, VertexFormat }; | ||
use crate::renderer::bidimensional::{Vertex, Vec2, Uniforms, Vec4}; | ||
|
||
pub struct Triangle; | ||
|
||
impl Renderable2D for Triangle { | ||
fn render(context: &mut Context) { | ||
let vertices: [Vertex; 3] = [ | ||
Vertex { pos: Vec2 { x: -0.5, y: -0.5 }, color: Vec4 { r: 1.0, g: 0., b: 0., a: 1.0, }, }, | ||
Vertex { pos: Vec2 { x: 0.5, y: -0.5 }, color: Vec4 { r: 0., g: 1., b: 0., a: 1.0 } }, | ||
Vertex { pos: Vec2 { x: 0., y: 0.5 }, color: Vec4 { r: 0., g: 0., b: 1., a: 1.0 } }, | ||
]; | ||
let vertex_buffer = Buffer::immutable(context, BufferType::VertexBuffer, &vertices); | ||
|
||
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3]; | ||
let index_buffer = Buffer::immutable(context, BufferType::IndexBuffer, &indices); | ||
|
||
let bindings = Bindings { | ||
vertex_buffers: vec![vertex_buffer], | ||
index_buffer, | ||
images: vec![], | ||
}; | ||
|
||
let shader = Shader::new(context, shader::VERTEX, shader::FRAGMENT, shader::meta()).unwrap(); | ||
|
||
let pipeline = Pipeline::new( | ||
context, | ||
&[BufferLayout::default()], | ||
&[ | ||
VertexAttribute::new("pos", VertexFormat::Float2), | ||
VertexAttribute::new("color", VertexFormat::Float4), | ||
], | ||
shader, | ||
); | ||
|
||
context.begin_default_pass(Default::default()); | ||
|
||
context.apply_pipeline(&pipeline); | ||
context.apply_bindings(&bindings); | ||
|
||
context.apply_uniforms(&Uniforms { | ||
offset: (0., 0.), | ||
}); | ||
|
||
context.draw(0, 3, 1); | ||
context.end_render_pass(); | ||
|
||
context.commit_frame(); | ||
} | ||
} | ||
|
||
mod shader { | ||
use miniquad::*; | ||
|
||
pub const VERTEX: &str = | ||
r#" | ||
#version 330 core | ||
in vec2 pos; | ||
in vec4 color; | ||
uniform vec2 offset; | ||
out lowp vec4 color_lowp; | ||
void main() { | ||
gl_Position = vec4(pos + offset, 0, 1); | ||
color_lowp = color; | ||
} | ||
"#; | ||
|
||
pub const FRAGMENT: &str = | ||
r#" | ||
#version 330 core | ||
in lowp vec4 color_lowp; | ||
out vec4 FragColor; | ||
void main() { | ||
FragColor = color_lowp; | ||
} | ||
"#; | ||
|
||
pub fn meta() -> ShaderMeta { | ||
ShaderMeta { | ||
images: vec![], | ||
uniforms: UniformBlockLayout { | ||
uniforms: vec![UniformDesc::new("offset", UniformType::Float2)], | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters