Benjamin100 wrote:Code: Select all
GLfloat projectionMatrix[]={(1/0.414), 0.0, 0.0, 0.0,
0.0, (1/0.414), 0.0, 0.0,
0.0, 0.0, (101/-99), (-200/-99),
0.0, 0.0, -1.0, 0.0};
To be in the correct form in the shader, this SHOULD need to be transposed ALSO. But it only works if I DON'T transpose it.
Because, the article I sourced that matrix from was an OpenGL article, and it was using column-major order to show matrices. As such, it is
already transposed. Transposing it again puts it into row-major order.
The first few paragraphs of this article reiterate the point I'm making. It also has a ton of other useful information if you care:
http://www.scratchapixel.com/lessons/3d ... ion-matrix
In summary, OpenGL programmers write matrices in column-major order, and mathematicians write them in row-major order. So if you're reading an OpenGL book, don't transpose them. If you're reading a Wikipedia article, you'll probably have to transpose them. As stated previously, the reason for this has to do with how you declare arrays in C++ and OpenGL's assumption that the 2nd element in the array is second row, first column (column-major) rather than first row, second column (row-major).
It could have happened either way, it's just bad luck and ignorance that we're stuck with differing norms than the mathematicians in this case. All the more reason to use a math library, or write some wrappers yourself to abstract this nonsense away from your daily work.