summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/lib.rs6
-rw-r--r--engine/src/renderer/mod.rs20
-rw-r--r--engine/src/vector.rs5
3 files changed, 22 insertions, 9 deletions
diff --git a/engine/src/lib.rs b/engine/src/lib.rs
index 618bc75..ea74fd1 100644
--- a/engine/src/lib.rs
+++ b/engine/src/lib.rs
@@ -3,6 +3,8 @@
use glfw::Window;
pub use glfw::WindowSize;
+use crate::vector::Vec2;
+
mod renderer;
pub mod vector;
@@ -27,6 +29,10 @@ impl Engine
.make_context_current()
.map_err(Error::ConfigureWindowFailed)?;
+ window.set_framebuffer_size_callback(move |new_window_size| {
+ crate::renderer::set_viewport(&Vec2::ZERO, &new_window_size);
+ });
+
crate::renderer::initialize(&window).map_err(Error::InitializeRendererFailed)?;
Ok(Self { window })
diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs
index c34441c..9cd379d 100644
--- a/engine/src/renderer/mod.rs
+++ b/engine/src/renderer/mod.rs
@@ -1,6 +1,8 @@
use std::ffi::{c_void, CString};
use std::process::abort;
+use glfw::WindowSize;
+
use crate::vector::Vec2;
pub fn initialize(window: &glfw::Window) -> Result<(), Error>
@@ -35,15 +37,7 @@ pub fn render()
}
}
-/// Renderer error.
-#[derive(Debug, thiserror::Error)]
-pub enum Error
-{
- #[error("Failed to get window size")]
- GetWindowSizeFailed(#[source] glfw::Error),
-}
-
-fn set_viewport(position: &Vec2<u32>, size: &crate::WindowSize)
+pub fn set_viewport(position: &Vec2<u32>, size: &WindowSize)
{
unsafe {
#[allow(clippy::cast_possible_wrap)]
@@ -55,3 +49,11 @@ fn set_viewport(position: &Vec2<u32>, size: &crate::WindowSize)
);
}
}
+
+/// Renderer error.
+#[derive(Debug, thiserror::Error)]
+pub enum Error
+{
+ #[error("Failed to get window size")]
+ GetWindowSizeFailed(#[source] glfw::Error),
+}
diff --git a/engine/src/vector.rs b/engine/src/vector.rs
index 92192bf..48550fa 100644
--- a/engine/src/vector.rs
+++ b/engine/src/vector.rs
@@ -4,3 +4,8 @@ pub struct Vec2<Value>
pub x: Value,
pub y: Value,
}
+
+impl Vec2<u32>
+{
+ pub const ZERO: Self = Self { x: 0, y: 0 };
+}