Public Group

#### Archived

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

# Color channels and bit shifting

This topic is 5260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, I have yet again another simple question. I am having a little trouble with getting the individual color channels from windows COLORREF. I have done this kind of thing with java before but I am not quite sure what I am doing wrong here. COLORREF is setup in this format: RED = 0x000000FF; GREEN = 0x0000FF00; BLUE = 0x00FF0000; I am using these functions to strip the color channels:
int particle::getR(void){

return (this->color & 0xFF);
}

int particle::getB(void){

return ((this->color & 0xFF0000)>>16);
}

int particle::getG(void){

return ((this->color & 0xFF00)>>8);
}

the color variable is in the same format as the colors define above. From the articles I''ve googled and the posted here on gamedev, it should work as far as I can tell. But it doesn''t seem to strip te channels correctly and most colors seem to be coming up as white or red. Any hlep would be greatly appreciated. Andy "And then 2 men appeared... Men in dark suits.. with dark soulless eyes. Men like this could have come from only one place..
The bank."

##### Share on other sites
I would probably write something like (color>>16)&0xff, but other than that it looks fine. Your problem is probably where you put the colours together.

##### Share on other sites
Hey Thanks for the reply. It turns out my problem was in the render and not in stripping the color channels. BTW I tried doing the masking and shifting like you suggested and it would turn a white color yellw(after I fix the reder problem).

Anyway thanks again.

Andy

"And then 2 men appeared... Men in dark suits.. with dark soulless eyes. Men like this could have come from only one place..
The bank."

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 9
• 9
• 46
• 41
• ### Forum Statistics

• Total Topics
631750
• Total Posts
3002062
×