BGRA not RGBA ?

Started by
6 comments, last by keethrus 21 years, 2 months ago
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
Advertisement
Is your source a .bmp file? If so, that file format reverses blue and red.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
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
In directx, the order is BGR, in GDI, it''s rgb, no mather what colour depth you''re useing

My Site
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
In DirectX, if you used a 4-byte array for colors, then the order is BGRA. It has nothing to do with your computer, your video card, or your current display mode. DirectX will always represent colors as BGRA.

~CGameProgrammer( );
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
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]
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]

This topic is closed to new replies.

Advertisement