Extracting the A,R,G and B from a D3DCOLOR

Started by
6 comments, last by jacksaccountongamedev 20 years, 4 months ago
Given a D3DCOLOR, how would I go about extracting the Alpha, Red, Green and Blue components into seperate ints?
Advertisement
Well, looking at MSDN, it says that D3DCOLOR is defined as:
typedef DWORD D3DCOLOR  

So, you should be able to extract the info as this:
a = (myColor >> 24) & 0xFF;r = (myColor >> 16) & 0xFF;g = (myColor >> 8) & 0xFF;b = myColor & 0xFF;  

... or the other way around (change the order of a r g b.. dunno about it)

edit: added alpha

[edited by - Jolle on December 13, 2003 6:41:39 AM]
Yep, your right, the order is 0xAARRGGBB, so use a bitwise AND '&&'. EDIT: I mean '&'... woops...

[edited by - PlayGGY on December 13, 2003 12:30:38 AM]
And the rockets' red glare, the bombs bursting in air,gave proof through the fight that our flag was still there.Oh say, does that star-spangled banner yet waveover the land of the free and the home of the brave?
quote:Original post by PlayGGY
Yep, your right, the order is 0xAARRGGBB, so use a bitwise AND ''&&''.


He did use a bitwise and. You''re using a logical and, and calling it bitwise. Please drink more coffee.
You could also use the GetRValue(), GetBValue(), and GetGValue() win32 functions. Check it out in msdn.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Yeah, but they doesn''t seem to have an GetAValue() :/
You would think that they would write those kind of functions down in the D3DCOLOR-document.
Thanks for the help. Im never good with this sort of thing...
quote:Original post by Namethatnobodyelsetook
quote:Original post by PlayGGY
Yep, your right, the order is 0xAARRGGBB, so use a bitwise AND ''&&''.


He did use a bitwise and. You''re using a logical and, and calling it bitwise. Please drink more coffee.


*cries* Your right... ''&''. Should have caught that.

And the rockets' red glare, the bombs bursting in air,gave proof through the fight that our flag was still there.Oh say, does that star-spangled banner yet waveover the land of the free and the home of the brave?

This topic is closed to new replies.

Advertisement