Ugh, did the followup email I sent not go through?
SDL_CreateTextureFromSurface was not using alpha because the surface’s A mask was 0.
When
I create the texture, I passed in default values of 0 for the R, G, B
and A masks, which means SDL should set them up properly.? This ends up
in SDL_MasksToPixelFormatEnum, where it hits the following code:
??? switch (bpp) {
??? …
??? …
??? …
??? case 32:
??? if (Rmask == 0) {
??? return SDL_PIXELFORMAT_RGB888;
??? }
This is obviously incorrect; RGB888 is a 24-bit pixel format with no alpha component.? Seems to me it should be returning SDL_PIXELFORMAT_RGBA8888.
Mason________________________________
From: Mason Wheeler <@Mason_Wheeler>
To: Mason Wheeler <@Mason_Wheeler>; SDL Development List
Sent: Saturday, August 10, 2013 9:47 AM
Subject: Re: [SDL] Alpha problems when creating programmatic textures
After a bit of debugging, I found something. It might not be exactly the problem I’m looking for, but it’s related.
SDL_CreateTextureFromSurface was not using alpha because the surface’s A mask was 0.
When I create the texture, I passed in default values of 0 for the R, G, B and A masks, which means SDL should set them up properly.? This ends up in SDL_MasksToPixelFormatEnum, where it hits the following code:
??? switch (bpp) {
??? …
??? …
??? …
??? case 32:
??? if (Rmask == 0) {
??? return SDL_PIXELFORMAT_RGB888;
??? }
This is obviously incorrect; RGB888 is a 24-bit pixel format with no alpha component.? Seems to me it should be returning SDL_PIXELFORMAT_RGBA8888.
Can anyone with more experience in SDL internals verify this?? Seems to me it’s an obvious bug, but is there some justification for it?
Mason
From: Mason Wheeler <@Mason_Wheeler>
To: sdl
Sent: Saturday, August 10, 2013 8:55 AM
Subject: [SDL] Alpha problems when creating programmatic textures
I’m having some problems with transparency.
I’m trying to do the following:
Create a SDL_Surface.
Fill it with blankness so that it’s completely
transparent
Draw several pixels on it
Create a texture from the surface
Render the texture
The problem is, when I render the texture, instead of only seeing the pixels I drew, I see the entire thing, with a black background.
I’ve made sure that the texture’s blend mode is set properly, and that the surface’s blend mode was set before calling SDL_CreateTextureFromSurface, but I’m still getting black backgrounds.
Here’s my code:
function CreateSurface(r, g, b: byte): PSdlSurface;
begin
?? result := TSdlSurface.Create(8, 20, 32);
?? if result.MustLock then
???
result.LockSurface;
?? result.Fill(nil, SDL_MapRGBA(result.Format, 0, 0, 0, 0)); //calls SDL_FillRect to fill the entire area
?? // drawing code here
?? if result.MustLock then
??? result.UnlockSurface;
end;
The output of this gets passed to a routine that sets the surface’s blend mode to SDL_BLENDMODE_BLEND, then calls SDL_CreateTextureFromSurface and sets the resulting texture’s blend mode to SDL_BLENDMODE_BLEND.? Not including it here because there are several layers involved to account for various special cases that don’t apply here, but at the core that’s what it does.
Anyone have any idea as to why the surface transparency isn’t being converted?
Mason
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org