[SDL] Cloud effect

David Olofson david at olofson.net
Tue Jul 25 14:24:30 PDT 2006


On Tuesday 25 July 2006 18:49, Salvatore Di Fazio wrote:
> Hi guys,
> does anybody know where I can find an example of 2d clouds like
> this: 
> 
> http://fi.wikipedia.org/wiki/Kuva:SNES_Chrono_Trigger.png

Some form of source alpha blending, most probably using a single "full 
surface alpha".

You can do this by using a color keyed source surface without an alpha 
channel, and setting the full surface alpha value with 
SDL_SetSurfaceAlpha(). This allows you to change the alpha (opacity) 
without modifying the source image.

Alternatively, use a source image with an alpha channel, and enable 
source alpha blending (ie per pixel alpha control by the alpha 
channel of the image) with SDL_SetSurfaceAlpha(). This allows you to 
vary the transparency to make thicker parts of the clouds actually 
look more dense, than rather just brighter. It also has the bonus of 
supporting antialiazing for smooth egdes around the clouds.


> or a shadow like this:
> 
> 
http://www.mobygames.com/game/snes/tales-of-phantasia/screenshots/gameShotId,53196/

Same thing, as above; just use a black mask image instead of clouds. 
You can still chose between colorkey + full surface alpha and source 
alpha channel, depending on your needs. (Real time alpha control vs 
per pixel alpha and/or antialiazing, that is.)


> or like this:
> 
> 
http://www.mobygames.com/game/snes/ogre-battle/screenshots/gameShotId,74153/

Looks like the cards are colorkeyed for transparency around the cards, 
and then displayed as an alpha blended layer over the opaque cloudy 
sky layer.

The text is either hardware sprites or a full screen colorkeyed layer. 
In SDL, you'd implement it using either colorkey or an alpha channel 
to control transparency per pixel. Again, the latter would allow 
antialiazing and partial transparency effects.


> I think it's an effect made by the alpha channel

Yep.

(I think per-layer alpha is the only type of blending implemented in 
the SNES hardware - which would explain why it is sometimes abused in 
cases where per pixel blending and/or other types of blending would 
have been more appropriate.)


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