The TL;DR of this question is, how do you load images in SDL 2.0 while
preserving their alpha values?
I recently attempted to migrate a small project of mine to SDL 2.0 from
1.2, and so far I have everything working, save for the alpha blending.
I’ve not actually taken advantage of the texture render, I’m still building
each frame from surfaces in software, then pushing the result out to the
GPU.
The way I’ve handled alpha blending previously is that my PNG images
contained the per pixel alpha data. I loaded surfaces using IMG_Load from
the SDL Image library, and then optimized them, as explained in tutorials,
by doing something like:
optimizedImage = SDL_DisplayFormatAlpha( loadedImage );
From what I understand, SDL_DisplayFormatAlpha() uses an internal variable
that stores the Display Format, and calls convert surface, and somehow adds
the alpha channel into all of this.
The function is gone from SDL 2.0 though, so I improvised based on my
understanding, by doing:
optimizedSurface = SDL_ConvertSurface( loadedSurface, Format, NULL );
where Format was obtained from: Format=Screen->format;
and Screen is an SDL Surface, tied to the window SDL 2.0 gives:
SDL Surface* Screen = SDL_GetWindowSurface( window );
Unfortunately, this causes me to lose the alpha values from my images. I’ve
tried going without the function, and therefore the optimization.
Everything works, including alpha, though the framerate slows to an
unplayable crawl.
Even if I’m to start using the more advanced features of SDL 2.0, I still
have the fundamental problem of loading these images correctly. Solutions
and insight are greatly appreciated.