While generally the available documentation on how the OpenGL matrices work is quite good, there are some missing bits. Although not necessary for your everyday rendering, they give one some insight on how rasterization in general and OpenGL in special works.

# W coordinate after perspective divide

After conversion to normalized device coordinates(ndc) one might think each vertex looks like

$$ \vec{v}_{ndc} = \frac{1}{w} \begin{pmatrix} x \\ y \\ z \\ w \end{pmatrix} = \begin{pmatrix} \frac{x}{w} \\ \frac{y}{w} \\ \frac{z}{w} \\ 1 \end{pmatrix} $$

however it looks more like

$$ \vec{v}_{ndc} = \begin{pmatrix} \frac{x}{w} \\ \frac{y}{w} \\ \frac{z}{w} \\ \frac{1}{w} \end{pmatrix} $$

the $w$ coordinate is not divided by itself, but is inverted instead. This is done because the interpolation between vertices still needs to take place and for perspective correct interpolation one needs the camera space depth $z = -w_{cam}$.

$$\begin{eqnarray}

\vec{v}_{\alpha} &=& \frac{(1-\alpha)\frac{\vec{v}_0}{-z_0} + \alpha\frac{\vec{v}_1}{-z_1}}

{(1-\alpha)\frac{1}{-z_0} + \alpha \frac{1}{-z_1}} \\

&=& \frac{(1-\alpha)\vec{v}_0 w_{0_{ndc}} + \alpha\vec{v}_1 w_{1_{ndc}}}

{(1-\alpha) w_{0_{ndc}} + \alpha w_{1_{ndc}}}

\end{eqnarray} $$

instead of dividing by $-z$ we can multiply with $w_{ndc}$ as multiplication is faster than division.

Note that for brevity the given formula assumes a scanline based rasterizer as it interpolates only between two vertices. The general approach is to use barycentric coordinates to interpolate between all three vertices simultaneously.

# Row major or column major

Even though even Wikipedia says OpenGL is column major, it is actually storage agnostic. However by default it interprets your 16 element array as:

$$ \begin{bmatrix}

m_0 & m_4& m_8 & m_{12}\\

m_1 & m_5& m_9 & m_{13}\\

m_2 & m_6& m_{10} & m_{14}\\

m_3 & m_7& m_{11} & m_{15}

\end{bmatrix}$$

Yet most OpenGL functions dealing with matrices offer a transpose parameter which you can use to specify the used order. For a comparison of storage orders see the Eigen documentation.