Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Matrices VS DirectX Matrices

I have only handled DirectX matrices

I have read articles that say you cannot use DirectX matrix math libraries for openGL matrices.

but i have also read that if your math is consistent you can get similar to same results. That just confuses me even more.

Can anyone enlighten me? or If you cannot use DirectX math on openGL matrices. Does anyone know a good openGL matrix library?

any help in understand the differences and math knowledge of them would be grateful.

like image 842
Franky Rivera Avatar asked Nov 10 '12 01:11

Franky Rivera


2 Answers

I have read articles that say you cannot use DirectX matrix math libraries for openGL matrices.

This is wrong.

but i have also read that if your math is consistent you can get similar to same results.

The only difference is about the default assumptions OpenGL and DirectX make about their Normalized Device Coordinate space. They use slightly different ranges and signs. However this only translates into a transformation stack with an additional "adaptor" matrix premultiplied on it, and you're done with.

Also important may be the index ordering, but modern OpenGL allows you to choose which order is used by a parameter to glUniformMatrix of the name "transpose"

like image 71
datenwolf Avatar answered Oct 02 '22 12:10

datenwolf


I'd like to add to datenwolf's great answer by making it clearer that the key perceived difference between OpenGL's matrices and DirectX's matrices is that they are in column-major and row-major formats, respectively. (Column- and row-major refers to how you would write them out in a 4x4 format. If the translations appear in the fourth column, that is column-major, vice versa for row-major.)

Mathematicians would tell you that column-major is the proper way to represent a matrix, primarily because it makes operations on them, visually (on paper), easier.

When it comes to OpenGL, however, the entire matrix is laid out contiguously in memory in a 16-element array, with the translation occupying the 13th, 14th, and 15th elements, according to the specifications. Thus, it's easy to adapt the data to either matrix format.

like image 32
kevintodisco Avatar answered Oct 02 '22 12:10

kevintodisco