opengl_learn

Step-by-step introduction to OpenGL
git clone https://0xdd.org/code/opengl_learn.git
Log | Files | Refs | README | LICENSE

ogl_program_uniform_set_mat4f.c (774B)


      1 /*
      2 2018 David DiPaola
      3 licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/zero/1.0/)
      4 */
      5 
      6 #include <stdio.h>
      7 
      8 #include <GL/glew.h>
      9 
     10 #include "ogl.h"
     11 
     12 int
     13 ogl_program_uniform_set_mat4f(
     14 	GLint program_ID, const char * uniform_name, const struct ogl_mat4f matrix
     15 ) {
     16 	GLint uniform_ID = 0;
     17 	int status = ogl_program_uniform_get_ID(program_ID, uniform_name, &uniform_ID);
     18 	if (status < 0) {
     19 		fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__);
     20 		return status;
     21 	}
     22 
     23 	const GLfloat * v = matrix.values;
     24 	const GLfloat   v_columnmajor[16] = {
     25 		v[ 0], v[ 4], v[ 8], v[12],
     26 		v[ 1], v[ 5], v[ 9], v[13],
     27 		v[ 2], v[ 6], v[10], v[14],
     28 		v[ 3], v[ 7], v[11], v[15],
     29 	};
     30 	glUniformMatrix4fv(uniform_ID, 1, GL_FALSE, v_columnmajor);
     31 
     32 	return 0;
     33 }
     34