Jump to content

  • Log In with Google      Sign In   
  • Create Account

Texture Matrix in DirectX vs OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Raptisoft   Members   -  Reputation: 171

Like
0Likes
Like

Posted 11 March 2014 - 06:07 AM

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

 



Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7991

Like
0Likes
Like

Posted 11 March 2014 - 06:16 AM

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.


Edited by Ashaman73, 11 March 2014 - 06:22 AM.


#3 mhagain   Crossbones+   -  Reputation: 8275

Like
0Likes
Like

Posted 11 March 2014 - 05:29 PM

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...


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 Burnt_Fyr   Members   -  Reputation: 1247

Like
0Likes
Like

Posted 12 March 2014 - 08:33 AM

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



#5 dpadam450   Members   -  Reputation: 945

Like
0Likes
Like

Posted 12 March 2014 - 04:20 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS