Texture Matrix in DirectX vs OpenGL

Started by
3 comments, last by dpadam450 10 years, 1 month ago

Hi all,

I have some code that has to be implemented in both DirectX and OpenGL ES 1.0 (meaning no shaders).

What I'm doing is setting the texture matrix. In DirectX via:


gDevice->SetTransform(D3DTS_TEXTURE0,((D3DMATRIX*)theMatrixPtr));

And in OpenGL via:


glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glLoadMatrixf((float*)theMatrixPtr);

I'm using this code right now only to TRANSFORM the texture matrix-- basically translating small fractions to make the texture scroll.

In DirectX I found that I have to put the translation numbers in a 3x3 matrix rather than a 4x4 matrix. I.E. the x/y transform coordinates have to go in matrix m20, m21 rather than what I use for all other transforms (m30,m31).

Is this also true in OpenGL? Or will OpenGL accept the texture coordinate transforms in m30,m31?

Thanks!

--John

Advertisement

OpenGl and DirectX use different coordination systems (the handness differs), so you cant use the same matrix for both APIs. At some point you need to convert them. Although opengl has 3 textures coord (when using 3d textures), but you can ignore this coord when using only uv-mapping. Though you still need a 4x4 matrix. If directX only handles uv-mapping, then a 3x3 matrix would be sufficient.

OpenGl and DirectX use different coordination systems (the handness differs), so you cant use the same matrix for both APIs. At some point you need to convert them. Although opengl has 3 textures coord (when using 3d textures), but you can ignore this coord when using only uv-mapping. Though you still need a 4x4 matrix. If directX only handles uv-mapping, then a 3x3 matrix would be sufficient.

I'm not sure how this applies to a texture matrix, and anyway D3D has had the capability to use right-handed coordinates since at least D3D8, if not earlier, so handedness differences haven't been relevant for a long time elsewhere either...

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I am not well versed in Open GL, but I think Ashaman73 hit the nail on the head. As you are translating the textures coordinates, you need a matrix with at least 1 more row/column(depending on whether or not you are using row vectors or column vectors) to perform an affine transformation. With 2D textures, a 3x3 matrix would suffice, as we have the 2x2 needed to perform any rotation, and an extra vector to represent translation. With 3D texture Coords, you would need a 4x4 matrix.

However, looking through this It appears that directx9 at least expects a standard 4x4 matrix here. Perhaps you could add some more information, or better yet code, so members may more easily help you out. Specifically I'd like know what version of D3d you are using, whether or not you're using shaders, and to see the calls to SetTextureStageState()l

openGL is column dependant

float[16] =
0 4 8 12

1 5 9 13

2 6 10 14

3 7 11 15

12 = x, 13 = y, 14 = z

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement