BGRA not RGBA ?
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
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
- jeremiah
inlovewithGod.com
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
- 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( );
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 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
More: http://sdldoc.csn.ul.ie/
[edited by - stefu on January 21, 2003 7:08:55 AM]
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
Popular Topics
Advertisement