Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL Alpha Blending

Started by Turt99 May 6, 2003 at 2:56 PM 0 replies 500+ views
Original Post
Turt99
Turt99
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
FOLLOW ME ON TWITTER OR MY BLOG
TravisWells
TravisWells
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.