SDL_RenderCopy alpha-blending strangeness

"geoffp" <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
Here's a strange thing: if an ARGB pixel with value 0x01ffffff (white, but nearly transparent) is
rendered onto a pixel with value 0 (completely transparent) by SDL_RenderCopy with default settings,
the rather surprising result is 0xff000000 (opaque black).

How can two nearly transparent pixels combine to make an opaque one?
Have I discovered a bug, or just my own ineptitude?

The effect is different with SDL_BlitSurface, which seems to stick to the formula for alpha-blending
given in SDL_blendmode.h :
   dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
     dstA = srcA + (dstA * (1-srcA)) 


The code I'm using (with SDL 2.0.4) is


Code:

SDL_Init(SDL_INIT_VIDEO);

// A target surface:
SDL_Surface *target_surf = SDL_CreateRGBSurface(0, 12, 12, 32, 0xff0000, 0x00ff00, 0x0000ff, 0xff000000);
SDL_FillRect(target_surf, NULL, 0x00000000);      // completely transparent
cout << "target's initial pixel value: " << hex << *((Uint32*)(target_surf->pixels)) << endl;
	 
// A surface to render onto the target:
SDL_Surface *src_surf = SDL_CreateRGBSurface(0, 12, 12, 32, 0xff0000, 0x00ff00, 0x0000ff, 0xff000000);
SDL_FillRect(src_surf, NULL, 0x01ffffff);         // white, but almost completely transparent
cout << "source pixel value: " << *((Uint32*)(src_surf->pixels)) << endl;

// Render to target_surf:
SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(target_surf);
SDL_Texture *src_texture = SDL_CreateTextureFromSurface(renderer, src_surf);
SDL_RenderCopy(renderer, src_texture, NULL, NULL);
cout << "resulting pixel value: " << *((Uint32*)(target_surf->pixels)) << endl;

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.