Comments on: GLSL 4×4 Matrix Fields https://www.geeks3d.com/20141114/glsl-4x4-matrix-mat4-fields/ Graphics Cards and GPUs News, Graphics Programming, Home of FurMark Fri, 24 Nov 2017 16:00:38 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: oldcrow https://www.geeks3d.com/20141114/glsl-4x4-matrix-mat4-fields/#comment-71488 Tue, 18 Nov 2014 07:58:46 +0000 http://www.geeks3d.com/?p=8941#comment-71488 This whole row-major vs column-major thing is really confusing because it depends how you look at your matrices; some books place the homogeneous components in the last column and use pre-multiplication in order to transform vectors, while other books place the homogeneous components in the last row of the matrix and use post-multiplication. Depending on how you are accustomed to writing your matrices, you may think that memory layout in OpenGL is row-major or column-major. The easiest way to avoid confusion is to drop the whole “row- column-major” thing and just remember that OpenGL places the translation components of matrices at the 13th, 14th, and 15th elements of a 16-element array. And as Damian Trebilco pointed out, both Direct3D and OpenGL use the same matrix layout.

]]>
By: slimy https://www.geeks3d.com/20141114/glsl-4x4-matrix-mat4-fields/#comment-71430 Tue, 18 Nov 2014 02:48:21 +0000 http://www.geeks3d.com/?p=8941#comment-71430 openGL is actually row major. People are confused by it because when they are looking at the modelview matrix they are looking at model * view and don’t consider that view is a transposed matrix.

Strictly model matrices (ie what you would pass to glMultMatrix) are row major. The first 4 values are the right vector. The next 4 the up vector, the next 4 the forward vector and the last 4 translation.

]]>
By: Damian Trebilco https://www.geeks3d.com/20141114/glsl-4x4-matrix-mat4-fields/#comment-71007 Fri, 14 Nov 2014 22:40:10 +0000 http://www.geeks3d.com/?p=8941#comment-71007 I will have to double check but I believe your memory layout ordering is wrong.

OpenGL is column major, but is laid out in memory in column order.

Eg. vec4 columns[4]; // First column is the first 4 memory slots

A little known fact is that the memory layout of OpenGL matrices is the same as DirectX!
(eg glTranslatef and D3DXMatrixTranslation should return the same in memory results)
http://www.mindcontrol.org/~hplus/graphics/matrix-layout.html

]]>