Advertisement Jump to content
Sign in to follow this  
Raptisoft

OpenGL Texture Matrix in DirectX vs OpenGL

This topic is 1775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

Share this post


Link to post
Share on other sites
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.

Edited by Ashaman73

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!