summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-05-23 11:50:54 -0500
committersanine-a <sanine.not@pm.me>2020-05-23 11:50:54 -0500
commita247c0adac7b3e50c72fde9b197ef6eabfd38b0b (patch)
treeea0c49821dca6bcc7829051724f5ad7df6f26020
parent86568ae07c04da1bfc2edbd029c677a73328c099 (diff)
add honey_shader_set_vec3()
-rw-r--r--demo.c2
-rw-r--r--demo.fs4
-rw-r--r--include/shader.h15
-rw-r--r--src/shader.c10
4 files changed, 27 insertions, 4 deletions
diff --git a/demo.c b/demo.c
index 1719914..dd55e7f 100644
--- a/demo.c
+++ b/demo.c
@@ -153,6 +153,8 @@ int main() {
honey_shader_set_int(shader, "box_texture", 0);
honey_shader_set_int(shader, "happy_texture", 1);
+ honey_shader_set_vec3(shader, "extra_color", (vec3){0, 0, 1});
+
glm_mat4_identity(model);
//glm_rotate_x(model, glm_rad(-55), model);
honey_shader_set_mat4(shader, "model", model);
diff --git a/demo.fs b/demo.fs
index 03159de..af6e190 100644
--- a/demo.fs
+++ b/demo.fs
@@ -2,6 +2,8 @@
in vec2 texture_coordinate;
+uniform vec3 extra_color;
+
uniform sampler2D box_texture;
uniform sampler2D happy_texture;
@@ -10,6 +12,6 @@ out vec4 FragColor;
void main()
{
FragColor = mix(texture(box_texture, texture_coordinate),
- vec4(texture(happy_texture, texture_coordinate).xyz, 1.0),
+ vec4(extra_color.xyz, 1.0),
0.2);
}
diff --git a/include/shader.h b/include/shader.h
index cbef3de..262b153 100644
--- a/include/shader.h
+++ b/include/shader.h
@@ -44,11 +44,20 @@ void honey_shader_set_int(honey_shader shader,
char* int_name,
int number);
-/** @brief Set a mat4 uniform
+/** @brief Set a vec3 uniform.
+ * @param[in] shader The shader to which the uniform belongs
+ * @param[in] vector_name The name of the vec3 uniform
+ * @param[in] vector The value of the vector uniform
+ */
+void honey_shader_set_vec3(honey_shader shader,
+ char* vector_name,
+ vec3 vector);
+
+/** @brief Set a mat4 uniform.
*
* @param[in] shader The shader to which the uniform belongs
- * @param[in] int_name The name of the matrix uniform
- * @param[in] number The value of the matrix uniform
+ * @param[in] matrix_name The name of the matrix uniform
+ * @param[in] matrix The value of the matrix uniform
*/
void honey_shader_set_mat4(honey_shader shader,
char* matrix_name,
diff --git a/src/shader.c b/src/shader.c
index d726523..530cc8f 100644
--- a/src/shader.c
+++ b/src/shader.c
@@ -99,6 +99,16 @@ void honey_shader_set_int(honey_shader shader,
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+void honey_shader_set_vec3(honey_shader shader,
+ char* vector_name,
+ vec3 vector) {
+ honey_shader_use(shader);
+ unsigned int vector_location = glGetUniformLocation(shader, vector_name);
+ glUniform3fv(vector_location, 1, (float*) vector);
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
void honey_shader_set_mat4(honey_shader shader,
char* matrix_name,
mat4 matrix) {