Archived

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

keethrus

BGRA not RGBA ?

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
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