Archived

This topic is now archived and is closed to further replies.

Turt99

SDL Alpha Blending

Recommended Posts

I''m working on a simple little game using SDL, now what I want to happen is when you complete a level, the background is set to be slightly transparent so that on a black background the image looks to be grayed out.. I''m guessing that this is done with Alpha blending somehow but I''ve never used it so I don''t really know how that would all work.. on the SDL site it shows a bunch of functions that deal with alpha blending but doesn''t really give an example on how to use them, so I was wondering if I was looking into the rigth technique and also if anyone can give a quick example on how I might go about doing this.. Please visit Turt99 Productions

Share this post


Link to post
Share on other sites
You'd want to do something like this:

/* This is the "You Win!" or whatever that you want to show
transparently over the game screen. (naturally, load it with a
bitmap or create the image) */
SDL_Surface *blended;
Uint8 amount=128; // Half transparent. 255 is opaque, 0 is full transparent.
SDL_SetAlpha(blended,SDL_SRCALPHA,amount);
SDL_BlitSurface(blended,NULL,screen_surface,NULL);



You could also supply dest or source Rects for the blit call, it doesn't affect blending.

If you want to use the blended surface later, in a non-blended manner, just call SDL_SetAlpha with 0 for the second argument.

[edited by - TravisWells on May 6, 2003 11:37:36 PM]

Share this post


Link to post
Share on other sites