Order of initializing matrices

The meaning of column-major in opengl has confused me.

A 4x4 matrix looks like this with the numbers representing the sequential order of each number,


1    5    9    13
2    6    10   14
3    7    11   15
4    8    12   16

Correct? So 1 - 4 might represent the x, y, z, and w of some vector…

Would I initialize a float array or a mat4 like this:


mat4(   1,  2,  3,   4,
        5,  6,  7,   8,
        9,  10, 11, 12,
        13, 14, 15, 16);

or like this?


mat4(   1, 5, 9,  13,
        2, 6, 10, 14,
        3, 7, 11, 15,
        4, 8, 12, 16);

Thanks for any help.

It’s simply a convention. You can use which ever convention suits you and your code base - but be consitent!
When you upload a matrix as a uniform, there are options to transpose or you could work with the Column-Major OpenGL convention in the first place.
Personally, I stick with the OpenGL column major approach which then makes interaction with any OpenGL matrix seamless.
To answer your last question, it depends on the approach you want to take. If you want column major, then
mat4( 1, 5, 9, 13,
2, 6, 10, 14,
3, 7, 11, 15,
4, 8, 12, 16);
is the way to do it and elements 13,14,15 represent the Translate (X,Y,Z) portion of the Matrix (eg when using glTranslatef command ).

[QUOTE=BionicBytes;1237665]It’s simply a convention. You can use which ever convention suits you and your code base - but be consitent!
When you upload a matrix as a uniform, there are options to transpose or you could work with the Column-Major OpenGL convention in the first place.
Personally, I stick with the OpenGL column major approach which then makes interaction with any OpenGL matrix seamless.[/QUOTE]

OpenGL requires column-major operator-on-the-left order:

PVM * v[SUB]obj[/SUB] = v[SUB]clip

[/SUB]
In your C++ code (which uses row-major ordered arrays), it’s simplest to use row-major operator-on-the-right order for your matrix storage and math:

v[SUB]obj[/SUB] * MVP = v[SUB]clip

[/SUB]
These two changes cancel each other out and you end up storing exactly the same values in exactly the same matrix locations, and there’s no need to do matrix transposes when passing matrix values to OpenGL.

Yep, totally agree with Dark Photon.
However, if like me you end up writing your own matrix and vector classes you need to debug them, and that’s where matching the OGL convention is so much easier. Once you then endup with something which works it’s then hard to justify changing the convention.

I see, thats very clear. Thank you.