"layering" surfaces

Hi Folks,

At work, some of our coders use an OpenGL library to “layer” surfaces, and it’s easy to use, eg:

surface.setDepth(value) - zero being at the front
surface.setVisible(boolean) - guess :wink:

So, with these simple commands (not to mention scaling, rotation, positioning, etc) we can easily display or hide surfaces.

My question is, does anything like this exist in SDL (either 1.2.x or the forthcoming 1.3)?

Unfortunately the library the guys here use was developed by a partner company and they will not let us have the source code, nor can we just re-use the library (it’s very bespoke).

Hope someone can help!

Many Thanks,
Ed___________________________________________________________
All New Yahoo! Mail ? Tired of unwanted email come-ons? Let our SpamGuard protect you. http://uk.docs.yahoo.com/nowyoucan.html

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.

At work, some of our coders use an OpenGL library to "layer"
surfaces, and it’s easy to use, eg:

surface.setDepth(value) - zero being at the front
surface.setVisible(boolean) - guess :wink:

So, with these simple commands (not to mention scaling, rotation,
positioning, etc) we can easily display or hide surfaces.

As was already mentioned, you can easily use OpenGL from within SDL.

While nothing exactly like what you’re describing exists within SDL,
I’m sure you could EASILY create a nice structure (containing perhaps
an SDL surface) which contains information like depth, size,
rotation, scale, position, etc… And a simple function which draws
these surfaces (updating the GL texture associated with each surface
structure, apply the proper GL transformations, draw using the GL
commands, etc…).

One could even abstract further drawing commands to use the surfaces
as arguments rather than drawing to the SDL surfaces within.

Of course, this is all if you want that sort of thing. I highly
recommend using OpenGL, however, in all cases. I’m sure what you
need wouldn’t be very difficult to come up with.

– Scott