Advertisement

D3D<->OpenGL matrices

Started by November 30, 2001 07:47 PM
5 comments, last by freazer 23 years, 2 months ago
Hey, I'm having a LOT of trouble creating an OpenGL renderer for an engine that was built for D3D. We've got the OGL and D3D renderer in different DLLs with the same commands: it's pretty nifty but a pain in ze tuckus for me ;-/ Anyway, the application creates the projection, view, and world matrices, then the three are passed to the DLL and processed. I read on MSDN that OpenGL uses tranposed matrices compared to D3D, but that IS NOT ENOUGH. My drawings are still screwed: http://staff.starcraft3d.net/freazer/tiny.jpg (supposed to look like a terrain grid/patch) I'm at a loss for what to do now, except for ask the guys to modify the rendering pipeline so camera coordinates and crap are passed.. but we shouldn't have to do that!! Pseudo code of what I'm doing: .. Projection Matrix: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glLoadMatrixf(transpose(passedD3DProjectionMatrix)); Modelview Matrix: tempModelViewMatrix = passedD3DViewMatrix * passedD3DWorldMatrix; // '*' represents matrix multiplication glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixf(transpose(tempModelViewMatrix)); .. I've looked everywhere and I.. haven't a clue of where to proceed from here. Anybody notice any anomalies like what I'm having in doing matrices between OpenGL and D3D? Edited by - freazer on November 30, 2001 8:59:14 PM
Vote to unban David Ho!
i''ve ever got such problem too.
however, i hadn''t notice the transpose matter at first. despite of the negligence, it worked well. so you can imagine how suprised i was when i noticed the matter.
finally, i found the memory layout of the matrix had just transposed it for me

in opengl:
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

in memory:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

notice the number, and that''s how it maps to opengl matrix.
i think so, tho'' not sure about it.
Advertisement
A VERY IMPORTANT NOTE:

when you transpose matrices, the order of matrix multiplication will also change.
You see in OpenGL vectors can be thought of as column vectors. ie when you want to transform it be a matrix, the matrix sits to the left of the vector. On the other hand in D3D, vectors are in row format, and therefore the matrices sit the their right.

This means that if you have two matrices, and you want their effects to be combined, A first then B, then:

In OpenGL : B*A
In D3D : A*B

note that in terms of where the vector sits in each format, it is always ''closest'' to A.

In your code, you are making this mistake:

D3DViewMatrix * D3DWorldMatrix

where as it should be:

D3DWorldMatrix * D3DViewMatrix

because you must first transform the vertex by the world matrix, then by the view matrix

Hope that helps
No luck so far :-(
Are the ways that World/View/Projection are generated universal between the two rendering APIs? Aside from the column/row major orders, are there perhaps any differences in generating the actual matrices themselves that could possibly result in the problems that I''m having?
Vote to unban David Ho!
as i know, opengl use right-handed coordinates, while d3d use left-handed. though world coordinates are different, camera coordinates are the same. triangles vertices are passed counter-clockwise by default, while clockwise in d3d.
could that help
quote:
Original post by Poya
In OpenGL : B*A
In D3D : A*B



Really?

I remember once I had a small graphics wrapper that supported both apis and I used same matrices for both (rows = vectors). Accidentally I don''t have it anymore.
Advertisement
In OpenGL : B*A
In D3D : A*B
i think these''re how OpenGL and D3D handle the matrices internally. but if you have your own math lib, it depends on your choice.

This topic is closed to new replies.

Advertisement