From 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Nov 2023 22:38:52 +0100 Subject: feat(engine): add basic flat lighting --- engine/src/opengl/shader.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'engine/src/opengl') diff --git a/engine/src/opengl/shader.rs b/engine/src/opengl/shader.rs index 3dc308e..4bf56aa 100644 --- a/engine/src/opengl/shader.rs +++ b/engine/src/opengl/shader.rs @@ -3,6 +3,7 @@ use std::ptr::null_mut; use crate::matrix::Matrix; use crate::opengl::currently_bound::CurrentlyBound; +use crate::vector::Vec3; #[derive(Debug)] pub struct Shader @@ -179,6 +180,41 @@ impl Program } } + pub fn set_uniform_vec_3fv( + &self, + _: &CurrentlyBound, + name: &CStr, + vec: &Vec3, + ) + { + let uniform_location = + unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; + + unsafe { + gl::Uniform3fv(uniform_location, 1, vec.as_ptr()); + } + } + + pub fn set_uniform_1fv(&self, _: &CurrentlyBound, name: &CStr, num: f32) + { + let uniform_location = + unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; + + unsafe { + gl::Uniform1fv(uniform_location, 1, &num); + } + } + + pub fn set_uniform_1uiv(&self, _: &CurrentlyBound, name: &CStr, num: u32) + { + let uniform_location = + unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; + + unsafe { + gl::Uniform1uiv(uniform_location, 1, &num); + } + } + fn get_info_log(&self) -> String { let mut buf = vec![gl::types::GLchar::default(); 512]; -- cgit v1.2.3-18-g5258