Matrix composition confussion GLES2 example

Hello

I’m trying to understand some GLES2 basic examples. In particular, I’m following this example here:
https://github.com/robclark/kmscube/blob/master/kmscube.c

The problem is it seems to be using some twisted matrix maths.
If we take a look at this call:

esMatrixMultiply(&modelviewprojection, &modelview, &projection);

we can see it’s composing the modelviewprojection matrix like this: modelview . projection
It’s ok, let’s suppose it’s because modelview and projection are column-major matrices, so we are obtainig the correct matrix but in column-major format. But then, why do we see this on the GLSL vertex shader?

"    gl_Position = modelviewprojectionMatrix * in_position;
"

This makes no sense at all: if we have a column-major modelviewprojection matrix, we should use it like this:

"    gl_Position = in_position * modelviewprojectionMatrix;
"

where in_position is a row-vector instead of the usual column vector.

My other question is: why does esRotate() produce row-major matrices while esFrustrum() produces column-major matrices? Makes no sense. One or the other, but why is it different in each one?

thanks

You’re mixing up column-major/row-major matrices with column/row vectors.

Ok, let’s see:
-In OpenGL, and in GLSL in particular, I think vectors are column vectors. So if matrices are NOT transposed, like in this case, matrices pre-multiply to them: MATRIX * vertex;
-If the modelviewprojection matrix is NOT transposed, then it should be composed like this:


esMatrixMultiply(&modelviewprojection, &projection, &modelview);

because projection is done AFTER modelview transformations, and NOT like this:


esMatrixMultiply(&modelviewprojection, &modelview, &projection);

So, what am I missing here, please?