skprime
skprime

Reputation: 55

Matrix4 to GLSL uniform value

So I'm creating a simple game in C++ with OpenGL API (Using SDL2 and GLEW).

I created simple shader program, and I started creating uniform variable loaders (Like a Vector3, float) but I really don't know how to load 4x4 Matrix to uniform variable with glUniformMatrix4fv.

How to put those values from my Matrix4 to this function?

Upvotes: 1

Views: 1235

Answers (1)

ratchet freak
ratchet freak

Reputation: 48196

glUniformMatrix4fv expects a pointer to a buffer with 16 floats.

float[16] m1;
struct mat4{
    float m00, m01, m02, m03;
    float m10, m11, m12, m13;
    float m20, m21, m22, m23;
    float m30, m31, m32, m33;
};
mat4 m2

The following are all valid:

glUniformMatrix4fv(MatUniformLoc, 1, GL_FALSE, &m2);
glUniformMatrix4fv(MatUniformLoc, 1, GL_FALSE, m1);

From the documentation:

count

For the matrix (glUniformMatrix*) commands, specifies the number of matrices that are to be modified. This should be 1 if the targeted uniform variable is not an array of matrices, and 1 or more if it is an array of matrices.

[...]

value

For the vector and matrix commands, specifies a pointer to an array of count values that will be used to update the specified uniform variable.

Upvotes: 2

Related Questions