Memory efficient transparent images

Hi, I’m looking to efficiently load some very large PNGs whose pixels are just black with varying levels of transparency.

It’s a waste of memory to use 32bpp for this (especially at the high resolutions involved), so I’m hoping to convert the surfaces to a max. 8bpp surface and still display the black colour with varying degrees of transparency per pixel.

I tried converting the surface to a slower bpp format but found that the resulting textures were all either solid black or solid white, with no transprency.

On iOS / UIKit, I was able to set the 8bpp images as the contents of a CALayer’s mask, and just set the layer’s backgroundColor to black.

I’d like to transfer this technique to SDL but I don’t really understand how SDL decides to transfer information between them, and also how to use the resultant alpha channel information as a “mask” to make semi-transparent pixels. Any help would be appreciated!

I’m not sure you can do this with the built in SDL renderer. You
might be able to use SDL_PIXELFORMAT_INDEX8 as the surface format.
Then, if the image loader you’re using is smart enough, it would create
an 8-bit palette with all of the colours as black and the alphas set
accordingly. And then assuming the Indexed Surface blitter really does
support alphas, it should work.

If you’re using OpenGL then you could just create an A8 format texture
for your data.

Ken, I realise your reply was years ago but better late than never: thank you for your reply!

Thanks to your insight we ended up going with SDL_gpu, which moved us closer to using OpenGL directly. We’ve since realised a better option would probably have been to use bgfx, which has fewer idiosyncrasies, but that’s hindsight for you. Using sdl_gpu we actually had to write our own shader to achieve the effect we were after here