glUniformMatrix4fv use with hmm_m4

Noob question. How do I use hmm_m4 with the OpenGL function below?

1
void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, Const GLfloat *value);


When I try, I get the error "void (GLint,GLsizei,GLboolean,const GLfloat *)': cannot convert argument 4 from 'hmm_m4 *' to 'const GLfloat *"
It looks like hmm_m4 is a double array of floats of size 4x4 with the name of the array as Elements.
So give something like this a try to give it a pointer to the first float location in the double array:

1
glUniformMatrix4fv(location, 1, GL_FALSE, &MatrixName.Elements[0][0]);



Edited by Kevin on
What is hmm_m4?

If it is POD (plain old data) type then casting it to float point will work fine, just take care transpose parameter:
1
2
hmm_m4 m = ...;
glUniformMatrix4fv(location, 1, transpose, (float*)&m);

Edited by Mārtiņš Možeiko on
Thanks Kevn, mmozeiko!

I ultimately went with mmozeiko solution for brevity. The data is POD and so the float * cast does the job perfectly.

1
2
3
4
5
6
typedef union hmm_mat4
{
    float Elements[4][4];
} hmm_mat4;

typedef hmm_mat4 hmm_m4;


Edit : Replacing glm with HMM improved by compilation time two fold. :)

Edited by Jesse on
Hello, and sorry for the late response!

In my own code base i do:

1
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP.Elements[0][0]); 


But your solution should work just fine :)

Thank you for using Handmade-Math, if its missing any features or if there is anything you would like to add i am accepting pull requests on the github page.
Thanks!