Handmade Math » Forums » glUniformMatrix4fv use with hmm_m4
JesseMeyer
Jesse
50 posts

None

#8040 glUniformMatrix4fv use with hmm_m4
11 months, 1 week ago

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 *"

The meaning of life is to dance and sing while the music is being played.
Kevn
Kevin
4 posts

None

#8041 glUniformMatrix4fv use with hmm_m4
11 months, 1 week ago Edited by Kevin on Aug. 13, 2016, 4:37 a.m.

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]);



None?
mmozeiko
Mārtiņš Možeiko
1397 posts
1 project
#8042 glUniformMatrix4fv use with hmm_m4
11 months, 1 week ago Edited by Mārtiņš Možeiko on Aug. 13, 2016, 8:01 a.m.

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);
JesseMeyer
Jesse
50 posts

None

#8046 glUniformMatrix4fv use with hmm_m4
11 months, 1 week ago Edited by Jesse on Aug. 13, 2016, 3:25 p.m.

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. :)

The meaning of life is to dance and sing while the music is being played.
strangezak
Zakary Strange
44 posts
3 projects

A C++ Programmer working on Squad professionally, and Proportion during my free time.

#8052 glUniformMatrix4fv use with hmm_m4
11 months, 1 week ago

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.

An angry programmer.
JesseMeyer
Jesse
50 posts

None

#8053 glUniformMatrix4fv use with hmm_m4
11 months, 1 week ago

Thanks!

The meaning of life is to dance and sing while the music is being played.