mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
refactor
This commit is contained in:
parent
dba53e4ceb
commit
fc71fda625
12
src/game.rs
12
src/game.rs
|
@ -24,9 +24,11 @@ pub fn run() {
|
||||||
log::info!("loading assets");
|
log::info!("loading assets");
|
||||||
let assets = Assets::load_all_sync(&display);
|
let assets = Assets::load_all_sync(&display);
|
||||||
log::info!("init camera");
|
log::info!("init camera");
|
||||||
let mut camera = Camera::default();
|
let camera = Camera {
|
||||||
camera.position = [0., 0., -1.];
|
position: [0., 0., -1.],
|
||||||
camera.direction = [0., 0., 1.];
|
direction: [0., 0., 1.],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
log::info!("game loaded");
|
log::info!("game loaded");
|
||||||
|
|
||||||
//=======================
|
//=======================
|
||||||
|
@ -37,7 +39,9 @@ pub fn run() {
|
||||||
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
||||||
//=======================
|
//=======================
|
||||||
|
|
||||||
|
|
||||||
event_loop.run(move |ev, _, control_flow| {
|
event_loop.run(move |ev, _, control_flow| {
|
||||||
|
#[allow(clippy::single_match, clippy::collapsible_match)]
|
||||||
match ev {
|
match ev {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
|
@ -56,7 +60,7 @@ pub fn run() {
|
||||||
target.clear_color_and_depth((0.5, 0.5, 1., 1.), 1.);
|
target.clear_color_and_depth((0.5, 0.5, 1., 1.), 1.);
|
||||||
target.draw(
|
target.draw(
|
||||||
&vertex_buffer,
|
&vertex_buffer,
|
||||||
&glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
|
glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
|
||||||
&programs.chunk,
|
&programs.chunk,
|
||||||
&uniform! {
|
&uniform! {
|
||||||
model: [[0.0f32; 4]; 4],
|
model: [[0.0f32; 4]; 4],
|
||||||
|
|
|
@ -6,7 +6,7 @@ fn load_png(file_path: &str, display: &glium::Display) -> SrgbTexture2d {
|
||||||
|
|
||||||
//Load file
|
//Load file
|
||||||
let data = fs::read(file_path)
|
let data = fs::read(file_path)
|
||||||
.expect(&format!("Failed to load texture: {}", file_path));
|
.unwrap_or_else(|_| panic!("Failed to load texture: {}", file_path));
|
||||||
|
|
||||||
//decode image data
|
//decode image data
|
||||||
let image_data = image::load(
|
let image_data = image::load(
|
||||||
|
|
|
@ -14,10 +14,6 @@ pub struct Camera {
|
||||||
pub zfar: f32,
|
pub zfar: f32,
|
||||||
}
|
}
|
||||||
impl Camera {
|
impl Camera {
|
||||||
pub fn new() -> Self {
|
|
||||||
Default::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view_matrix(&self) -> [[f32; 4]; 4] {
|
pub fn view_matrix(&self) -> [[f32; 4]; 4] {
|
||||||
let position = self.position;
|
let position = self.position;
|
||||||
let direction = self.direction;
|
let direction = self.direction;
|
||||||
|
|
|
@ -8,5 +8,5 @@ use glium::glutin::{
|
||||||
pub fn init_display(event_loop: &EventLoop<()>) -> Display {
|
pub fn init_display(event_loop: &EventLoop<()>) -> Display {
|
||||||
let wb = WindowBuilder::new();
|
let wb = WindowBuilder::new();
|
||||||
let cb = ContextBuilder::new().with_depth_buffer(24);
|
let cb = ContextBuilder::new().with_depth_buffer(24);
|
||||||
Display::new(wb, cb, &event_loop).unwrap()
|
Display::new(wb, cb, event_loop).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use glium::{Display, Program, implement_vertex};
|
use glium::implement_vertex;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Vertex {
|
pub struct Vertex {
|
||||||
|
|
Loading…
Reference in a new issue