This project has moved and is read-only. For the latest updates, please go here.

FXMVECTOR and color

Aug 6, 2012 at 10:40 PM

Stupid question, what is the correct usage of the XMFLOAT2 and XMVECTOR parameters in the draw methods.  Currently I'm doing something like:

XMVECTOR color = { r, g, b, a };
SpriteBatch->Draw(sprite, XMFLOAT2(pos.x, pos.y), color);

Where pos in my custom float2 struct.  Which works fine, but feels verbose.  Is there a better way?

Also, is there a way to pass color without explicitly defining it before calling the method?  Sometimes I'd like to just do something like:

SpriteBatch->Draw(sprite, XMFLOAT2(pos.x, pos.y), XMVECTOR(r, g, b, a));

(Which, of course, doesn't compile...)


Aug 7, 2012 at 4:32 AM

Why not make a simple helper function thingy like below?

XMVECTOR Colour(float r, float g, float b, float a)
    XMVECTOR colour = { r, g, b, a };
    return colour;

And then when you need to do something with colour, you can call it like so.

SpriteBatch->Draw(sprite, XMFLOAT2(pos.x, pos.y), Colour(r, g, b, a));
Aug 7, 2012 at 7:40 AM


There's also a ton of predefined color constants in DirectXColors.h header in the DirectX::Colors namespace.

Aug 7, 2012 at 4:53 PM

Thanks!  That was exactly what I was looking for.