[SDL] Blitting through an Intermediary
David Olofson
david at olofson.net
Mon Apr 26 08:30:06 PDT 2004
On Monday 26 April 2004 14.20, Brian wrote:
[...alpha & intermediate surface...]
I'm doing that in Fixed Rate Pig (http://olofson.net/examples.html),
in order to avoid some clipping overhead when using RLE acceleration.
The basic procedure is as follows:
1. Load the image. (Let's call it tmp.)
2. Disable alpha blending;
SDL_SetAlpha(tmp, 0, 0);
3. For each target surface (tmp2), create an RGBA
surface:
tmp2 = SDL_CreateRGBSurface(SDL_SWSURFACE,
sw, sh, 32,
0xff000000, 0x00ff0000,
0x0000ff00, 0x000000ff);
3b. Disable alpha blending for the target surface:
SDL_SetAlpha(tmp2, 0, 0);
3c. Blit the area(s) you want as usual:
SDL_BlitSurface(tmp, &rect, tmp2, NULL);
3d. Enable alpha blending for the target surface:
SDL_SetAlpha(tmp2, SDL_SRCALPHA | SDL_RLEACCEL,
SDL_ALPHA_OPAQUE);
3e. (For performance) convert the surface to a suitable
format for blitting to the screen:
sprite = SDL_DisplayFormatAlpha(tmp2);
And of course, don't forget to SDL_FreeSurface() the temporary
surfaces. (Note that SDL_DisplayFormat*() creates a new surface
without freeing the original surface.)
//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
mailing list