Archived

This topic is now archived and is closed to further replies.

johnnyBravo

Is there any difference between RGB and D3DCOLOR_XRGB

Recommended Posts

quote:
Original post by quasar3d
no, they are not the same, they store the values in a different order. By example, if you pass RGB(255,0,0) as a D3DCOLOR, it will be blue instead of red.

My Site


I don't think that is entirely accurate. D3DCOLOR_XRGB is a macro which calls another macro called D3DCOLOR_ARGB. D3DCOLOR_XRGB allows you specify the red, green and blue colors and automatically passes 255 as the alpha color. Its useful when you are not using an alpha channel, such as when you set the background color of your scene with the Direct3DDevice->Clear() method.

The definition of D3DCOLOR_XRGB.

The definition of D3DCOLOR_ARGB.

Edit: Oh and to answer your question...

Yeah there is a difference. RGB is a 24-bit color format. 8-Bits are given for each color (Red, Green and Blue). There is also a 16-Bit RGB format. Five bits for red and blue and six bits for green.

XRGB is a 32-Bit format. 8-Bit for red, green and blue and the other eight bits are thrown away (You could also possibly use them to store other information for certain rendering effects).

ARGB is the real deal. Those other eight bits are used for the alpha channel.

Hope that helps a bit.


[edited by - Reaptide on January 16, 2004 11:50:16 PM]

Share this post


Link to post
Share on other sites
RGB only uses the lowest 24 bits, but a COLORREF is typedefed as an unsigned long, so it''s 32 bits too. But because d3d uses the highest byte as alpha, XRGB sets it to 0xff, while RGB just leaves it at 0.
But the order of the colours is swapped too. as you can see, d3d has blue in the lowest byte, then green, then red, and the alpha chanel in the highest byte. RGB has red in the lowest byte, then green and blue, and the highest byte is just left at 0.

#define D3DCOLOR_ARGB(a,r,g,b) \
((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))

#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))

My Site

Share this post


Link to post
Share on other sites