[SDL] 'Cutting a Hole' in a Surface

David Olofson david at olofson.net
Tue Nov 27 10:53:04 PST 2007


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  --'


More information about the SDL mailing list