Original Post
Hi, earlier, i had some problems with my sprite rendering function but when i made it work, this new problem popped up. There is something wrong with the colors. The image i load is an TIFF image and i use the SDL_Image library to load it. Uint32 fh_renderer::a_blend( unsigned int bg, unsigned int fg) { int bg_r = (bg >> 0) & 0xff; int bg_g = (bg >> 8) & 0xff; int bg_b = (bg >> 16) & 0xff; int fg_r = (fg >> 0) & 0xff; int fg_g = (fg >> 8) & 0xff; int fg_b = (fg >> 16) & 0xff; float bg_a = ( ( bg >> 24 ) & 0xff ) / 255.0; float fg_a = ( ( fg >> 24 ) & 0xff ) / 255.0; bg_a = 1 - ( 1 - fg_a ) * ( 1 - bg_a ); bg_r = bg_r + ( fg_a * ( fg_r - bg_r ) ); bg_g = bg_g + ( fg_a * ( fg_g - bg_g ) ); bg_b = bg_b + ( fg_a * ( fg_b - bg_b ) ); int int_bg_a = bg_a * 255; return (bg_r << 0) | (bg_g << 8) | (bg_b << 16) | (int_bg_a << 24); }
If i switched bg_r with bg_g it rendered in the right way. int bg_b = (bg >> 0) & 0xff; int bg_g = (bg >> 8) & 0xff; int bg_r = (bg >> 16) & 0xff; But that doesnt feel logical, does it? At least not to me... SDL_BlitSurface rendered it in the right way so it cant be that it loaded the image in a wrong way...
If i switched bg_r with bg_g it rendered in the right way. int bg_b = (bg >> 0) & 0xff; int bg_g = (bg >> 8) & 0xff; int bg_r = (bg >> 16) & 0xff; But that doesnt feel logical, does it? At least not to me... SDL_BlitSurface rendered it in the right way so it cant be that it loaded the image in a wrong way...