From 54c0fd70f82eb1a6814872c78bc22380f438c9d1 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 22 Oct 2023 19:29:11 +0200 Subject: feat(engine): add translating & scaling objects --- engine/src/renderer/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'engine/src/renderer/mod.rs') 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) +pub fn render<'obj>(objects: impl IntoIterator) { 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); }); } -- cgit v1.2.3-18-g5258