-
Notifications
You must be signed in to change notification settings - Fork 513
Color
DirectXTK | SimpleMath |
---|
Four component color vector class modeled after the XNA Game Studio 4 (Microsoft.Xna.Framework.Color
) math library.
#include <SimpleMath.h>
using namespace DirectX::SimpleMath;
Color c; // Creates opaque black
Color c(1, 1, 1); // Creates opaque white
Color c(1, 1, 1, 0.5f); // Creates white with 50% alpha (straight-alpha)
Color c( Vector3(1,1,1) ); // Creates opaque white
Color c( Vector4(1,1,1,0.5f); // Creates white with 50% alpha (straight-alpha)
float arr[4] = { 1, 1, 1, 1 };
Color c(arr); // Creates opaque white
- x is the red component of the color
- y is the green component of the color
- z is the blue component of the color
- w is the alpha component of the color
- R: Red component
- G: Green component
- B: Blue component
- A: Alpha component
- Comparison operators:
==
and!=
- Assignment operators:
=
,+=
,-=
,*=
,/=
- Unary operators:
+
,-
- Binary operators:
+
,-
,*
,/
-
BGRA: Converts to a
DirectX::PackedVector::XMCOLOR
Direct3D 9 style color equivalent toD3DCOLOR
. -
RGBA: Converts to a
DirectX::PackedVector::XMUBYTEN4
XNA Game Studio style packed color - ToVector3
- ToVector4
-
Negate: Negates or inverses the color. The result is
Color( 1 - x, 1 - y, 1 - z, w )
. - Saturate: Clamps the color to the 0 to 1 range
- Premultiply: Converts straight-alpha color to premultiplied alpha
- AdjustSaturation: A parameter of 0 returns the grey-scale of the color, 1 returns the original color
- AdjustContrast: A parameter of 0 returns 50% grey of the color, 1 returns the original color
- Modulate: Blends two colors together
- Lerp: Linearly interpolates between two colors
Color can freely convert to and from a XMFLOAT4
and XMVECTOR
When assigning a color from DirectXColors.h
to a Color, use the .v
union element
Color color = Colors::White.v;
Color can be copy and assigned from DirectX::PackedVector::XMCOLOR
(BGRA Direct3D 9 D3DCOLOR packed color) and DirectX::PackedVector::XMUBYTEN4
(RGBA XNA Game Studio packed color).
Color component values can exceed the 0 to 1 range for High Dynamic Range (HDR) lighting. Alpha values greater than 1 typically don't have a valid meaning.
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20