Send the matrix to shader in java(model * view * projection)

Started by Mihai_Ionut_Floares, November 11, 2020, 20:59:49

Previous topic - Next topic


If i built my own matrix and vector classes and I have the model matrix, the view matrix and the projection matrix as 2d arrays and I multiply them with with:
for(int n = 0;n<4;n++) {
			for(int i = 0;i<4;i++) {
				for(int j = 0;j<4;j++) {
					result.mat[i][n] += mat1.mat[i][j] * mat2.mat[j][n];

I get a mat4 class(the matrix class). The array is located in the class:
mat4x4.mat(the mat is the array name and the mat4x4 is a new mat4 class/object)

and at final after multiplying, I need to send it to the vertex shader and I tried like this:
mat4 MVP = new mat4();

//MVP = the multiplication of model, view and projection matrice
int MatrixID = glGetUniformLocation(programID, "MVP");
//the main loop
FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(16);// IDK why 16
glUniformMatrix4fv(MatrixID, true, floatBuffer);

This doesn't work, the triangle is on the entire screen like before, seen as 2d and now the OpenGL ignores the fragment shader. In the frag shader I told it to draw the triangle blue and it was blue, but fter I tried to send the matrix to the vertex shader like above, the trangle is white, so it isn't compiling the fragment shader. 
The question is how to send the final MVP matrix to the shader, because I don't think GLSL knows about my mat4 class. Should I send only the array component(mat4x4.mat  where mat4 mat4x4 = new mat4()), or what shoud I send to GLSL and how to deal with the floatBuffer parameter. I couldn't find on google anything about that.

The SimpleVertexShader.vertexshader:
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
uniform mat4 MVP;
void main(){
  gl_Position =  MVP * vec4(vertexPosition_modelspace,1);
  transformed_vertex = MVP * in_vertex;