OpenGL Matrices VS DirectX Matrices
Asked Answered
D

2

5

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.

Downe answered 10/11, 2012 at 1:45 Comment(1)
looks like they are different: mindcontrol.org/~hplus/graphics/matrix-layout.html. related: #3696020. opengl.org/discussion_boards/showthread.php/…. they are probably just transposes of each other: en.wikipedia.org/wiki/TransposeSyblesybley
M
5

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"

Monochasium answered 10/11, 2012 at 1:53 Comment(2)
so what your saying is if i use my math library i made for directX when i pass my matrices just make sure to check that transpose boolean?Downe
@FrankyRivera: That and you your projection matrices need some translation-scaling premultiplied to them. IIRC Scale(0.5, 0.5, -1) · Translate(1, 1, 0) but don't nail me down on it.Monochasium
S
3

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.

Swoosh answered 10/11, 2012 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.