Sunday, March 25, 2007

Color macro in DirectX

Quick post but I ran into a macro that is defined in d3d9types.h that accepts 4 float values and returns and a single DWORD. This came up when I was working with the lighting pipeline in DirectX 9. Specifically, there is a fundamental difference in the way vertex diffuse/specular colors are stored (DWORDs) and the way DirectX materials are stored (D3DCOLORVALUEs aka. 4 floats).

definition:

#define D3DCOLOR_COLORVALUE(r, g, b, a)
D3DCOLOR_RGBA((DWORD)((r)*255.f), (DWORD)((g)*255.f), (DWORD)((b)*255.f), (DWORD)((a)*255.f))

No comments: