All the talk of implementing multiple windows got me thinking again
about a feature of SDL I always thought would be cool - the ability to
create surfaces which were really just sub-rectangles of other surfaces.
Great for split-screen multiplayer support!
I think allegro has this feature - at least it did 10 years ago when I
was using it on DOS, and I really liked it. Seemed lovely and elegant.
Anyway, I’ve attached a patch (against the latest from CVS) and a noddy
little demo program.
The patch implements an extra surface flag (SDL_SUBSURFACE), three extra
fields in SDL_Surface (uhoh!), and a new API call: SDL_CreateSubSurface().
I think it maintains binary compatibility. As long as apps use SDL to
allocate and free surfaces, then the extra fields on SDL_Surface
shouldn’t be a problem. And even if an app does alloc it’s own
SDL_Surface structs on the heap or stack, SDL wouldn’t ever attempt to
read the (missing) extra fields unless the SDL_SUBSURFACE flag is set…
(actually I think my patch might need a slight tweak to ensure this).
I don’t think adding a new API call to the library breaks binary
compatibility, but I could be wrong about that…
Anyway, I don’t have any particular vested interest in this feature (not
doing any split-screen games at the moment :-). I just thought it’d be
fun to implement, so I’m not too worried or offended if it falls in the
bit bucket.
But hopefully someone might find it useful!
docs for the new API call:----------------------------------------------------
Synopsis:
SDL_Surface *SDL_CreateSubSurface( SDL_Surface *parent, const SDL_Rect
*area );
Description:
Creates a surface which is really just an sub-area of a parent surface.
The subsurface is like a window on to the parent. Drawing to the subsurface
draws directly to the parent.
If a parent surface is the screen, then the subsurface can also be
treated as
a screen. That is, SDL_UpdateRect() SDL_UpdateRects() should work as
expected
on a subsurface of the screen (internally, the rectangles will be mapped to
the screen).
Subsurfaces have the internal flags SDL_SUBSURFACE and SDL_PREALLOC set.
Relevant fields in SDL_Surface:
parent: points to the parent surface
parent_x: x position of subsurface on the parent
parent_y: y position of subsurface on the parent
Ben.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: subsurface.patch
Type: text/x-patch
Size: 5389 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050622/5e62b9f5/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed…
Name: subsurfacetest.c
Type: text/x-csrc
Size: 1410 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050622/5e62b9f5/attachment.c