Handmade Math»Forums
Jesse
64 posts
Programmer at NASA GSFC
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 *"
Kevin
4 posts
None
glUniformMatrix4fv use with hmm_m4
Edited by Kevin on
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]);


Mārtiņš Možeiko
2559 posts / 2 projects
glUniformMatrix4fv use with hmm_m4
Edited by Mārtiņš Možeiko 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);
Jesse
64 posts
Programmer at NASA GSFC
glUniformMatrix4fv use with hmm_m4
Edited by Jesse 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. :)
43 posts / 1 project
glUniformMatrix4fv use with hmm_m4
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.
Jesse
64 posts
Programmer at NASA GSFC
glUniformMatrix4fv use with hmm_m4
Thanks!