Jump to content
  • Advertisement


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


32 bit color macro

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

hello, i have tricks of the windows game programming gurus, and the 32 bit color macro doesn''t work. could someone help me and give me one that does. i don''t understand macros(like this one, i understand simple ones) and bit shifting, could someone explain that too. thanks

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
It took me a little while also, to understand what exactally the macro did(and I''m still not positive I have it correct!), but this is how I understand it. I also have the book, and I think I see the problem. If you look on page 300, it has the macro as:

#define _RGB32BIT(a,r,g,b) ( + ((g) << 8) + ((r) << 16) + ( << 24

If you use this you''ll get some really odd errors. It''s a simple typo in which they forgot the ''b'' at the begining and the ''a'' twords the end. TheSalmon posted the correct code. Here is my understanding of it:

First, take b and add it to (g<<8). So you figure out g<<8 which would shift the green value ''up'' 8 bits. Thoses 8 bits are where the blue value will be going. Then add that to the red value which was shifted ''up'' 16 bits, and then add that to the alpha which was shifted ''up'' 24 bits. Here is a little diagram:

00000000 00000000 00000000 00000000
Add the b value (lets assume b is 10101010 = 85)
10101010 00000000 00000000 00000000
Next, add the g value that was shifted by 8(lets assume g = 11110000 = 15)
If we shift it by 8 we get 00000000 11110000 so we now have:
10101010 11110000
Now, add the red which was shifted by 16(lets assume r = 00001111 = 240)
If we shift it by 16 we get 00000000 00000000 00001111 so now:
10101010 11110000 00001111
Last, we add the a value shifted 24(assume a = 11111111 = 255)
Shifting it by 24 yeilds 00000000 00000000 00000000 11111111
All together we get:
10101010 11110000 00001111 11111111
(b << 0) (g << 8) (r<< 16) (a << 24)

Hope this helps!

"I kinda think, therefore, I kinda... am?"

Share this post

Link to post
Share on other sites
thanks everyone, the macro does work, and i understand the bit shifting thing a lot more now. these forums are great, everyone is so helpfull.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!