[SDL] "layering" surfaces
Ryan C. Gordon
icculus at icculus.org
Wed Feb 14 14:42:49 PST 2007
> My question is, does anything like this exist in SDL (either 1.2.x or
> the forthcoming 1.3)?
You could just use OpenGL inside SDL...this is going to be your best bet.
If you need to do it with a 2D surface, you have your work cut out for you.
You can draw back-to-front (so the surface with a depth of -1 gets drawn
before the surface with a depth of zero). This will naturally layer them
as you wish, since the one "on top" will overwrite the parts of the
things below it that overlap so the final result looks correct. If you
have a lot of pixels to move, this can be very inefficient...ten
surfaces that completely overlap will all get blitted when you could
have just blitted one for the same result...but it will work and it's
simple to write and maintain.
Faster: draw front-to-back, and only draw things that you know won't be
covered. This can get REALLY complicated...you'll either want to walk
through all the surfaces and build a list of rectangles, and then blit
bits and pieces of each surface as it would be on the screen, or use
something called a "span list" (google for that one). This code can get
complicated and unreadable.
Extra credit for not blitting parts of the screen that didn't change
between frames.
Scaling and rotation make it worse by an order of magnitude. SDL doesn't
provide these functions and a lot of shortcuts you could take in
building spanlists, etc, go away when you can't count on the size or
shape of the surface.
But really, just use OpenGL. You might as well dump all the data to the
GL without any consideration and let the hardware sort it out for
you...and get the massive speed boost, too.
--ryan.
More information about the SDL
mailing list