Jump to content
  • Advertisement
Sign in to follow this  
stenny

getting the R, G, of B from a D3DCOLOR

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

G'day, Finally back from an internetless vacation. I've had this question in my head for the complete 3 weeks (yeah, I encountered the problem right at the first day), and didn't know how to handle. Does anyone kow how to get the R, G and B values (seperate) from a D3DCOLOR and put them in an int? I hope someone can help. -Stenny

Share this post


Link to post
Share on other sites
Advertisement
Well, a D3DCOLOR is just a packed ARGB value.
So:

D3DCOLOR col = D3DCOLOR_ARGB(1, 2, 3, 4);

int a = (col&0xff000000) >> 24;
int r = (col&0x00ff0000) >> 16;
int g = (col&0x0000ff00) >> 8;
int b = (col&0x000000ff) >> 0;

Share this post


Link to post
Share on other sites
Alternately, shift first, then and with '0xff' always (for example, g = (col >> 8) & 0xff). I find it simpler.

Another way is to define a union with a bit field, which could result in clearer code, and give the compiler more leeway for optimisation.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!