Sign in to follow this  
DimaSi

OpenGL D3D and OpenGL projection matrices

Recommended Posts

Hi! Why D3D and OpenGL have different projection matrices ? Basically, functions that create this projection matrices has same IN parameters: (fov, aspect, z_near, z_far) but math behind creating this matrix is little bit different. Thx for answers.

Share this post


Link to post
Share on other sites
They don't have different projection matrices. What you are talking about is handedness (right and left) of matrices and coordinate systems. The right and left handedness are mere conventions. To say that one is different from the other is wrong. It is up to you to decide which one (handedness) you want to use. Direct3D offers APIs to create both types.

D3DXMatrixPerspectiveFovLH - Left handed.
D3DXMatrixPerspectiveFovRH - Right handed.

True, OpenGL doesn't offer an API for left-handed system out of the box, or rather GLU doesn't, but you can write your own function to create a left-handed matrix for OpenGL.

If you set left-handed matrices, you can make OpenGL behave exactly like Direct3D or vice-versa.

Share this post


Link to post
Share on other sites
D3D maps the depth 0.0 to 1.0 while GL maps to -1.0 to 1.0 and then remaps to 0.0 to 1.0 using another functionality (glDepthRange)
Don't worry, you don't lose performance.

D3DX also has 2 functions. One for right handed and another for left.

I think that element [3][3] of the D3DX projection matrix version is incorrect.

It is zf/(zn-zf) instead of (zf+zn)/(zn-zf)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this