Jump to content
  • Advertisement
Sign in to follow this  

DX11 different colors when using XMVECTOR or XMFLOATs

This topic is 2087 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

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

Share this post

Link to post
Share on other sites

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

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!