Hello Guest

Send 2d array to uniform mat4 matrix

  • 1 Replies
  • 45 Views
Send 2d array to uniform mat4 matrix
« on: November 12, 2020, 19:14:26 »
Hi, I posted a similar question but I get no answer so I simplify it in this forum. Please do not mark as duplicate. If I have a 2d float array like (float[][] transformMatrix = new float[][]) I want to send it to the shader to be used with the inPosition:
Code: [Select]
void main()
    {

        gl_Position = transformation * in_Position;
    }

I tried like this:
Code: [Select]
glUseProgram(programID);


for(int i = 0; i < 4;i++) {
for(int j = 0;j<4;j++) {
matrix44Buffer.put(transformation.mat[i][j]);
}
}
glUniformMatrix4fv(MatrixLocation, false, matrix44Buffer);

       


matrix44Buffer.flip();

       
         
        glUseProgram(0);

It isn't working. How to send the float[][] to the shader? All the websites that I found were using JOML or lwjgl 2 which has its own matrices.
« Last Edit: November 12, 2020, 19:25:37 by Mihai_Ionut_Floares »

Re: Send 2d array to uniform mat4 matrix
« Reply #1 on: November 13, 2020, 20:50:07 »
I succeed I need to convert the 2D position/rotation/scale/projection array(float[][]) into a 1D float array(float[])
Ex(I have this scale matrix as a float[][]):
2 0 0 0
0 2 0 0
0 0 2 0
0 0 0 1

I needed to put in a float[] like that:
2 0 0 0 0 2 0 0 0 0 2 0 0 0 0 1

and then send the float[] directly to GLSL without any float buffer like that:
Code: [Select]
glUseProgram(programID);
int MatrixID = glGetUniformLocation(programID, "theMatrix");
glUniformMatrix4fv(MatrixID, false, translationArray);

glUseProgram(0);