[SDL] 'Cutting a Hole' in a Surface
Leeor
leeor_net at yahoo.com
Tue Nov 27 16:49:09 PST 2007
David Olofson <david <at> olofson.net> writes:
>
> On Tuesday 27 November 2007, Leeor wrote:
> [...]
> > I've tried a few things that don't seem to be working as well as I
> > would have liked. Any suggestion on how I can 'cut a hole' in a
> > surface?
>
> You have to use colorkeying, or create the surface with an alpha
> channel, otherwise the only thing you can draw into the surface is
> opaque color.
>
> > Also, I've thought of just using a few Rect's or a Rect list to kind
> > of draw around the 'hole' but I don't see this as being too feasible
> > in a real-time sense with the light source bouncing around.
>
> This is probably *faster*, actually. Indeed, if you're using RLE, the
> transparent area is just skipped, so that's the fastest way you can
> do it - but accelerated backends still have to read the transparent
> pixels.
>
> Either way, the number of rectangles aren't going to make a difference
> unless you have hundreds of them - or thousands, if we're talking
> about current generation PCs.
>
> But, why don't you just clear the screen, set up a clip rect and
> render through that...?
>
> //David Olofson - Programmer, Composer, Open Source Advocate
>
> .------- http://olofson.net - Games, SDL examples -------.
> | http://zeespace.net - 2.5D rendering engine |
> | http://audiality.org - Music/audio engine |
> | http://eel.olofson.net - Real time scripting |
> '-- http://www.reologica.se - Rheology instrumentation --'
>
Thank you for your response! I'm not sure why I didn't think of it before but
using a color key to cut a hole in a layer makes a lot of sense! I'm going to
try it now... actually, I expect it to work. May not be the fastest of all
methods but it should certainly do the trick (considering the sections to cut
out will never be more than about 128x128.)
As for clip rects, that also seems feasible... problem is I've never been too
sure how to use them. Go figure... *^_^ I'm not too terribly concerned about
performance anyway because I don't see a couple of the 'holes' causing much of
a performance bottleneck... of course, I could be wrong! :)
Thank you for taking the time to reply!
More information about the SDL
mailing list