Jump to content
  • Advertisement

Archived

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

Pulse_Phalanx

SDL Bmp transparency

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone knows an instruction or a way to display an Bmp image using SDL but with transparent background. I searched and a found this function ,SDL_SetColorKey, but i don''t understand how it works. thx in advance!

Share this post


Link to post
Share on other sites
Advertisement
It''s easy.

Here is an example using SDL_img to load the picture and blue as the transparent color :

SDL_Surface picture = IMG_Load("picture.png");
SDL_SetColorKey(picture, SDL_SRCCOLORKEY, SDL_MapRGB(picture->format, 0, 0, 255));

I hope that helps.

Andy

Share this post


Link to post
Share on other sites
The other way of course is to use PNG formats that have a full alpha channel. You can then have 255 levels of "transparent". However, setting the color key is faster and not having any transparancy is MUCH faster than blitting a png image (about 2.5x)

Share this post


Link to post
Share on other sites
hey leave, what do you mean by 255 levels of transparency? are you talking about alhpha blending, as in one portion of the image could be 0% transparent, another could be 1%, 2%, all the way to 255??

Share this post


Link to post
Share on other sites
There is a free book available in pdf format which uses SDL. It nicely explains most of it''s features and their usage in a different language then the docs. So it may help when trying to understand the usage of something...

Programming Linux Games

granted, you may not use linux, but sdl is cross-platform, so anything discussed about it will work on windows also.


------------------------------------------------------------
// TODO: Insert clever comment here.

Share this post


Link to post
Share on other sites
quote:
Original post by C-Junkie
yes. exactly what he said. an alpha channel.


Just dont''t go crazy with the alpha blending. Using a lot of it can really kill framerates in SDL.

Share this post


Link to post
Share on other sites
As mentioned, it''s called the "alpha channel". See, you have 3 regular channels: Red, Green, and Blue. Each channels takes up 8 bits (for true color). The alpha channel is another 8 bits that describes the pixel''s transparency . Like the other color channels, it has 256 possible values. PNG images are especially cool because they, unlike BMPs, have data for that alpha channel. When you call the image loading function, it should create a blended surface for you that picks up whatever alpha data your original image has.

To learn more about alpha, just play around in any decent image editor. If you don''t have one, pick this one up for free. It''s quite nice:

http://www.gimp.org/

And just to be repetetive, don''t go alpha blending everything. Blitting a fully alpha-blended SDL surface to the screen of a different format can be anywhere from 2x-5x more expensive and you''ll just slaughter your framerate. If you game is not action oriented, you may get away with it. If you need really smooth animation, only use it where you absolutely have to.

Share this post


Link to post
Share on other sites
drowner posted a link that i am interested in however it''s not working. does anybody know how else i could get my hands on that information

Share this post


Link to post
Share on other sites
quote:
Original post by graveyard filla
hey leave, what do you mean by 255 levels of transparency? are you talking about alhpha blending, as in one portion of the image could be 0% transparent, another could be 1%, 2%, all the way to 255??


Remember, a while ago, I was working on some window class that had a solid border and a transluscent background, and had problems because of how my surfaces were organized?

That's alpha blending. And yes, it does a number on the framerate. A 640x480 image blitted every frame as a background ran at about 60 FPS on my PC using SDL (PIII 650 with an ATI RAGE 128; there were a few other things being blitted but they used an insignificant amount of overhead in terms of framerate approximations). A ~420x200 50% transluscent window (edit: without that background; ie, this is a comparaison between just a 640x480 bg and just a ~420x200 window) dropped to 40 FPS. It's nothing horrible, but I can imagine a number of painful slow-downs in a tile-based game with a background, tiles, sprites, and some text/numbers being blitted every frame...

Just don't abuse it and you'll be fine. SDL makes it REALLY easy to use.

[edited by - RuneLancer on May 4, 2004 2:38:53 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!