• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

# different colors when using XMVECTOR or XMFLOATs

2 replies to this topic

### #1savail  Members   -  Reputation: 298

Like
0Likes
Like

Posted 28 October 2013 - 12:17 PM

So I'm following a tutorial http://www.rastertek.com/dx11tut04.html and managed to convert it from D3DX10math.h to DirectXMath.h but I can't get the same color values when using XMVECTOR or XMFLOATs for my vertices. I want to draw a green triangle and this is how I set positions and colors for vertices using XMVECTOR:

//vertices::position and vertices::color are XMVECTORs alligned to 16 bytes

vertices[0].position = DirectX::XMVectorSet(-1.0f, -1.0f, 0.0f, 0.0f);  // Bottom left.
vertices[0].color = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);

vertices[1].position = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);  // Top middle.
vertices[1].color = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);

vertices[2].position = DirectX::XMVectorSet(1.0f, -1.0f, 0.0f, 0.0f);  // Bottom right.
vertices[2].color = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);

This gives me totally blue triangle, whereas such solution:

//vertices::position is XMFLOAT3 and vertices::color is XMFLOAT4

vertices[0].position = XMFLOAT3(-1.0f, -1.0f, 0.0f);  // Bottom left.
vertices[0].color = XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f);

vertices[1].position = XMFLOAT3(0.0f, 1.0f, 0.0f);  // Top middle.
vertices[1].color = XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f);

vertices[2].position = XMFLOAT3(1.0f, -1.0f, 0.0f);  // Bottom right.
vertices[2].color = XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f);

with types changed to XMFLOAT3 for position and XMFLOAT4 for color gives me correct green triangle.

I've played a bit with these coordinates and tried to make a green triangle using XMVECTORs but it doesn't seem to have any sense. The XMVECTOR solution returns wrong colors all the time whatever I set the coordinates to...

I know that it might be hard to guess what's the problem without some details but maybe somebody has an idea of what might be wrong?

PS: When I change the last parameter in XMVECTOR solution for vertices::position to 1.0f it changes the color near that vertex to pink, which is completely wierd for me as position shouldn't have impact on color?

Edited by savail, 28 October 2013 - 12:25 PM.

### #2Zaoshi Kaba  Crossbones+   -  Reputation: 2165

Like
5Likes
Like

Posted 28 October 2013 - 02:24 PM

Just making sure... XMFLOAT3 and XMVECTOR are different size, did you change input layout & vertex strides to match that?

Edited by Zaoshi Kaba, 28 October 2013 - 02:29 PM.

### #3savail  Members   -  Reputation: 298

Like
0Likes
Like

Posted 28 October 2013 - 03:06 PM

Thank you very much! Indeed, I had to change the format for my position in the layout from DXGI_FORMAT_R32G32B32_FLOAT to DXGI_FORMAT_R32G32B32A32_FLOAT and now everything works correctly! Thanks a lot again... there is so much to learn in DX 11 that one can easily get confused .

PARTNERS