Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As I read in OpenGL matrices are column major. It means that if I create a 16 element array first four elements are the first column in matrix. Is it the same for Direct3D or any transformation's required.

share|improve this question
up vote 7 down vote accepted

Heishe is right about memory layout and matrices being the same, but his answer is somewhat misleading. Such things as right-handed or left-handed matrices don't exist. Be it a right- or left- handed coordinate system, math and the matrix stays the same, matrix operations give the same result for both of these systems. How we will interpret the data later, thats the difference.

In OpenGL, matrix operations are pre-concatenated, which means concatenated transformations are applied from right to left. Direct3D, however, applies concatenated transformations from left to right.

So what you need to do is to match the order of operation in OpenGL to the order of Direct3D. When writing OpenGL code, you apply the transform that you want to occur first last; when writing DirectX you're doing the opposite. Let's say you just transformed vector v in OpenGL by matrices A and B: v' = ABv In Direct3D the same transformation would be v' = vBA.

share|improve this answer
Thanks for the clear explanation. Could you please tell whether the storage I.e. memory layout of a matrix class matters in the system (OpenGL or DirectX) used? – legends2k Jan 30 '13 at 7:46

DirectX matrices are right-handed and OpenGL requires left handed matrices, but while OpenGLs matrices are column-major, DirectX's matrices are row-major, so they're layout in memory is the same.

share|improve this answer
OpenGL matrices are definitely NOT left-handed (and cooridnate systems neither). – Christian Rau Aug 15 '11 at 17:38

Neither D3D nor OpenGL specify or enforce a matrix handedness. True, the matrix stack functions in OpenGL are RH, but there's absolutely nothing to stop you from writing your own matrix library (or using a 3rd party one) that uses LH coords and loading the result using glLoadMatrixf. Likewise D3D has a full set of both RH and LH matrix functions. This is an old old old misunderstanding and needs to be put to bed.

Regarding row-major vs column major, please see the following:

Column-major versus row-major is purely a notational convention. Note that post-multiplying with column-major matrices produces the same result as pre-multiplying with row-major matrices. The OpenGL Specification and the OpenGL Reference Manual both use column-major notation. You can use any notation, as long as it's clearly stated.

Sadly, the use of column-major format in the spec and blue book has resulted in endless confusion in the OpenGL programming community. Column-major notation suggests that matrices are not laid out in memory as a programmer would expect.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.