[SDL] RGBA->RGBA blitting again
david at olofson.net
Thu Nov 27 05:04:00 PST 2003
On Thursday 27 November 2003 13.30, MagerValp wrote:
> I'm writing a small font library that prints text to a transparent
> overlay, which is then displayed on the screen when a key is held
> down. The code works fine as long as the font is stored in a
> colorkeyed surface, but when I copy it to an RGBA surface with
> SDL_DisplayFormatAlpha for faster blitting, the text itself becomes
Yes... That's because RGBA->RGBA blits don't apply the source alpha
the way you'd expect. (Performance reasons, I guess.)
> I searched the archives, and I guess this is an old
> problem, but this limits me to slow blits with 1-bit alpha and no
> anti-aliased fonts. You can see my test code here:
Nice little font, BTW. Reminds me of great old Atari ST and Amiga
> Is there a workaround for this?
The easy solution, if you don't have too much text on the screen, is
to just render directly to the screen. This is how it's done in Kobo
Deluxe, and the text "overlays" only have a slight effect on the
frame rate on very low end hardware, as far as I've seen.
If you need massive amounts of text, you're probably better off
rendering the overlay surfaces with your own blitting code, that
applies/combines alpha the way you want. If there's no overlapping,
you could just copy the full pixels from the font surface. Limited
overlapping could be handled by cheating; just or the source and
destination alpha together. Note that if you change the overlay
surfaces frequently, the rendering and RLE decoding/encoding overhead
will become significant.
BTW, don't ask for a 32 bpp display unless you absolutely need it to
be exactly 32 bpp. If you run that code in windowed mode, or on a
target that can't switch to 32 bpp, you'll get a shadow rendering
buffer that is converted and blitted to the screen when you flip. Not
insanely expensive if you're doing full screen s/w rendering anyway,
but for more normal applications it eliminates any chances of using
h/w accelerated blits.
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
More information about the SDL