Register
Handmade Math»Forums»glUniformMatrix4fv use with hmm_m4
Jesse
55 posts

None

glUniformMatrix4fv use with hmm_m4
3 years, 3 months 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.
Kevin
4 posts

None

glUniformMatrix4fv use with hmm_m4
3 years, 3 months 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?
Mārtiņš Možeiko
1983 posts / 1 project
glUniformMatrix4fv use with hmm_m4
3 years, 3 months 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);
Jesse
55 posts

None

glUniformMatrix4fv use with hmm_m4
3 years, 3 months 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.
Zakary Strange
46 posts / 3 projects

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

glUniformMatrix4fv use with hmm_m4
3 years, 3 months 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.
Jesse
55 posts

None

glUniformMatrix4fv use with hmm_m4
3 years, 3 months ago
Thanks!

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