# Color transparency with SDL?

This topic is 4918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

1. iS there anyway to set a color transparency with SDL? OR is there anyway to make the image im moving always under the last one I used? (For a tetris game ) 2. Since i'm going to make a Tetris game, that mean i will load more than 5 images, and moslty an uncertain amount of images. Is there a way beside : SDL_Surface *Piece1; SDL_Surface *Piece2; SDL_Surface *Piece3; SDL_Surface *Piece4; etc. Like only use one for all the piece. [Edited by - deathwearer on August 4, 2005 11:31:33 PM]

##### Share on other sites
Quote:
 Original post by deathwearer1. iS there anyway to set a color transparency with SDL?

You mean a color key?

Quote:
 OR is there anyway to make the image im moving always under the last one I used? (For a tetris game )

Not sure what you're asking, but sounds like it's a simple issue of drawing stuff in the right order.

Quote:
 2. Since i'm going to make a Tetris game, that mean i will load more than 5 images, and moslty an uncertain amount of images. Is there a way beside :SDL_Surface *Piece1;SDL_Surface *Piece2;SDL_Surface *Piece3;SDL_Surface *Piece4;etc. Like only use one for all the piece.

Well, you could do something like this:
SDL_Surface *Pieces[5];

Or you could just have all the pieces on one big surface, and then blit that portion of the surface whenever you need to draw a piece.

##### Share on other sites
1. Yes maybe a color key, i have pieace for tetris game but they of course all have some black around em and i would like to make it transparent.

2. The 2 solution sound good, but i wonder, when you blit the piece on the surface, that mean that it is now part of the background? so i can delete the pointer and use it again?

3. Also when you load an image, and then blit it with the backgound if it's possible, do i have to load the image once again?

[Edited by - deathwearer on August 5, 2005 9:22:01 AM]

##### Share on other sites
You can either use alpha blending, or SDL_SRCCOLORKEY.

You can only use color keying on 24 or less-bit surfaces(that is, no alpha channel). Use SDL_SetColorKey(your_surface,SDL_SRCCOLORKEY,SDL_MapRGB(your_surface->format,red_value,green_value,blue_value));
once before the first blit.
Otherwise, fire up some image editor, and make the black areas literally transparent.

##### Share on other sites
Ok Thank, i think it will be alright for the color transparency.

Now, concerning your post BradDaBug, are you saying i could "blit" one of the piece on the background?

If so when i'v done this, what shall i do before i re-use the image pointer?

##### Share on other sites
When you blit a surface on to another (such as the screen) it basically does a straight copy of the image data. This means that you can reuse the image without reloading it just fine.

##### Share on other sites
In your main loop, the first thing you should do is either clear the whole screen or reblit the whole background onto the screen. After that, you should blit all of the peices onto the screen, not the background.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 42
• ### Forum Statistics

• Total Topics
634131
• Total Posts
3015717
×