0
\$\begingroup\$

I am importing my code from OpenGL to Direct3D. My D3DTS_PROJECTION uses D3DXMatrixPerspectiveFovRH, and my D3DTS_VIEW uses D3DXMatrixLookAtRH to set a view equal to OpenGL's view. My question is why do I have to switch all of my 1.0000 Tex(v) texture coordinates to "minus value" in D3D to get equal texture mapping as in OpenGL.

OpenGL:

//T(u) T(v) 1.0000, 1.0000, 0.0000, 1.0000, 1.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.0000, 0.0000, 1.0000, 0.0000, // ... 

Direct3D:

// T(u) T(v) D3DXVECTOR2( 1.0000f, -1.0000f) D3DXVECTOR2( 0.0000f, -1.0000f) D3DXVECTOR2( 1.0000f, 0.0000f) D3DXVECTOR2( 1.0000f, 0.0000f) D3DXVECTOR2( 0.0000f, -1.0000f) D3DXVECTOR2( 0.0000f, 0.0000f) D3DXVECTOR2( 0.0000f, -1.0000f) D3DXVECTOR2( 0.0000f, 0.0000f) D3DXVECTOR2( 1.0000f, -1.0000f) D3DXVECTOR2( 1.0000f, -1.0000f) D3DXVECTOR2( 0.0000f, 0.0000f) D3DXVECTOR2( 1.0000f, 0.0000f) // ... 

Is it because Direct3D's origin (0.0) of texture coordinates lies in different place than in OpenGL?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

For texture spaces, in Direct3D (0, 0) is top-left, in OpenGL (0, 0) is bottom-left. Therefore the v-coordinate will be upside down in one of these APIs.

However, I wouldn't recommend negating the v-coordinate as this will only work if you're using a sampler with wrapping.

You can fix the v-coordinate as follows:

v = 1.0f - v; 
\$\endgroup\$
2
  • \$\begingroup\$ And also negating them will create inaccurate results if you are going to do any sort of transformation with the uv´s. or create some sort of data from it. \$\endgroup\$ Commented Apr 7, 2014 at 12:06
  • \$\begingroup\$ Thank you for your answer! This is just what I needed. No more "minus values" in texture coordinates and the final effect is equal to OpenGL's. \$\endgroup\$ Commented Apr 7, 2014 at 17:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.