Jump to content
  • Advertisement

Archived

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

keethrus

BGRA not RGBA ?

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

im messing around with some graphics functions and it seems that on this computer im using, in 32-bit color mode (which i thouht was 1 byte RED, 1 byte GREEN, 1 byte BLUE, 1 byte alpha) has the RGB backwards (1 byte BLUE, 1 byte GREEN, 1 byte RED, 1 byte alpha). is this a common setup or do different computers do things differently? - jeremiah inlovewithGod.com

Share this post


Link to post
Share on other sites
Advertisement
well, im not talking about any source. when i output 0xFF000000 to the screen, its blue instead of red. and when i output 0x0000FF00 its red instead of blue. and green, being in the middle, is green.

- jeremiah

inlovewithGod.com

Share this post


Link to post
Share on other sites
im using SDL so i assume under windows SDL uses directx. whats gdi by the way? well, since im wanting to keep my code portable, should i have some sort of option to reverse the RGB/BGR order in case their computer uses the RGB?

- jeremiah

inlovewithGod.com

Share this post


Link to post
Share on other sites
I'm just guessing, but are you setting up a dword (ie DWORD pixData = 0xFF000000; ) then writing it to the appropriate place in the buffer (eg. (DWORD)screen[45][76] = pixData; ) ???

If you are then you will be falling foul of intel's little-endian byte ordering; basically when an intel chip writes a dword to memory it writes the bytes in reverse order (ie so the least significant byte comes first).

What happens if you access the buffer as bytes & specifically write the components into the correct byte positions in the buffer?

[edit] silly forum replaced my ; )'s with smilies...doh!

[edited by - NickB on January 21, 2003 6:42:20 AM]

Share this post


Link to post
Share on other sites
If you use SDL, you know the pixel format of the surface. Then use functions

Uint32 SDL_MapRGBA(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);


More: http://sdldoc.csn.ul.ie/


[edited by - stefu on January 21, 2003 7:08:55 AM]

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.

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!