SDL_CreateTextureFromSurface() mangles 24-bit surfaces

If you try to call SDL_CreateTextureFromSurface() on a 24-bit surface, it creates a 32-bit texture, then calls SDL_UpdateTexture on the surface’s Pixels field without any conversion, leading to a badly distorted result. This can be worked around, but it’s awkward due to the lack of an external API call to create a SDL_PixelFormat independently of a surface.

convert1 = SDL_CreateRGBSurface(0, 1, 1, 32, 0, 0, 0, 0);
convert2 = SDL_ConvertSurface(surface, convert1->format, 0);

textureID = SDL_CreateTextureFromSurface(0, convert2);

This really ought to be done inside of SDL_CreateTextureFromSurface.

2009/7/26 Mason Wheeler :

If you try to call SDL_CreateTextureFromSurface() on a 24-bit surface, it
creates a 32-bit texture, then calls SDL_UpdateTexture on the surface’s
Pixels field without any conversion, leading to a badly distorted result.

Have you submitted a bug report?

No. I’ve got a working patch, but when you consider the number of patches I’ve
already submitted which are just sitting around in the Bugzilla DB gathering dust,
some several months old, that creates a bit of a disincentive to submit any
more…

2009/7/26 Mason Wheeler <@Mason_Wheeler>:

If you try to call SDL_CreateTextureFromSurface() on a 24-bit surface, it
creates a 32-bit texture, then calls SDL_UpdateTexture on the surface’s
Pixels field without any conversion, leading to a badly distorted result.

Have you submitted a bug report?From: llubnek@gmail.com (Kenneth Bull)
Subject: Re: [SDL] SDL_CreateTextureFromSurface() mangles 24-bit surfaces

This should be fixed in the latest SDL 1.3 snapshot.On Sun, Jul 26, 2009 at 7:07 PM, Mason Wheeler wrote:

If you try to call SDL_CreateTextureFromSurface() on a 24-bit surface, it
creates a 32-bit texture, then calls SDL_UpdateTexture on the surface’s
Pixels field without any conversion, leading to a badly distorted result.
This can be worked around, but it’s awkward due to the lack of an external
API call to create a SDL_PixelFormat independently of a surface.

??? convert1 = SDL_CreateRGBSurface(0, 1, 1, 32, 0, 0, 0, 0);
??? convert2 = SDL_ConvertSurface(surface, convert1->format, 0);

??? textureID = SDL_CreateTextureFromSurface(0, convert2);

This really ought to be done inside of SDL_CreateTextureFromSurface.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC