diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-22 19:29:11 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-22 19:29:11 +0200 |
commit | 54c0fd70f82eb1a6814872c78bc22380f438c9d1 (patch) | |
tree | 7b0b67b52daa7ce18432c7b83caa862234a3255c /engine/src/renderer/mod.rs | |
parent | 30394c16ccdcdb145352e245a7a8893cef28e82d (diff) |
feat(engine): add translating & scaling objects
Diffstat (limited to 'engine/src/renderer/mod.rs')
-rw-r--r-- | engine/src/renderer/mod.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index 8ca85e2..068b8f0 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -1,8 +1,10 @@ use std::ffi::{c_void, CString}; use std::process::abort; +use cstr::cstr; use glfw::WindowSize; +use crate::object::Object; #[cfg(feature = "debug")] use crate::opengl::debug::{MessageSeverity, MessageSource, MessageType}; use crate::opengl::shader::Program as ShaderProgram; @@ -92,14 +94,18 @@ fn opengl_debug_message_cb( }; } -pub fn render<'renderable>(renderables: impl IntoIterator<Item = &'renderable Renderable>) +pub fn render<'obj>(objects: impl IntoIterator<Item = &'obj Object>) { clear_buffers(BufferClearMask::COLOR); - for renderable in renderables { - renderable.shader_program.activate(); + for obj in objects { + obj.renderable().shader_program.activate(); - renderable.vertex_arr.bind(|vert_arr_curr_bound| { + obj.renderable() + .shader_program + .set_uniform_matrix_4fv(cstr!("transform"), &obj.transform().as_matrix()); + + obj.renderable().vertex_arr.bind(|vert_arr_curr_bound| { VertexArray::draw(&vert_arr_curr_bound, PrimitiveKind::Triangles, 0, 3); }); } |