Install mat4 in OpenGL

I read several (basic) shader guides. While they covered how to set variables in your shader. But it was only about ints, float or vector. I can not find anything about how to set mat4 variable. My shader expects the following:

uniform vec3 CameraPos;
uniform mat4 ModelWorld4x4;

So, the position of the camera and the world matrix of the model. I think I have CameraPos correctly, but how can I set the ModelWorld4x4 variable ??


This is how I installed vector3

campos = glGetUniformLocation(shader.id(), "CameraPos");
glUniform3f(campos, 0.0f, 0.0f, 3.0f);

This (one of the methods), as I tried to install mat4

glGetFloatv(GL_MODELVIEW_MATRIX, modelworld);
modelw = glGetUniformLocation(shader.id(), "ModelWorld4x4");
glUniformMatrix4fv(g_modelworld4x4, modelworld); // Not working

I use the Assimp library to load the model, so the world matrix is ​​currently stored in the aiMatrix4x4 structure.

// world matrix of the model
aiMatrix4x4 m = nd->mTransformation;

// Save in a global variable
g_modelworld4x4 = m;
+5
source share
2 answers

, ModelWorld4x4 , . , g_modelworld4x4 - float *, :

int location = glGetUniformLocationARB(program, "ModelWorld4x4");
glUniformMatrix4fvARB(location, 1 /*only setting 1 matrix*/, false /*transpose?*/, g_modelworld4x4;

ARB , .

+10

glUniformMatrix4fv , .

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

glUniformMatrix4fv (modelw, 1, GL_FALSE, modelworld), ( , - .) GL_TRUE, .

+5

All Articles