Pleae help! making a transparant background using SDL_image?/

high,

im new to this whole mailing list thing. but hello everyone. im a fairly new
programmer and i love SDL. ive just recently (almost) finished my first 2d
game using this wonderfull API. its a pong clone (what else?). anyway, the
game is pretty much done, BUT, before i released it to have others play/test
it, i wanted to change all of my images from .bmp to a .jpg or something
else thats small. i cant be sending this game out with all bmp’s cause then
the file would be huge!!! anyway, heres the problem : i downloaded SDL_image
and i installed everything. first thing i did was change my intro screen to
a .jpg, then in my code i changed the line

data.intro = SDL_LoadBMP(“intro.bmp”);

to

data.intro = IMG_Load(“intro.jpg”);

everything worked fine! so im all excited, thinking this would work. i then
change all my in game objects(the paddle’s and ball) from bmps to jpgs in
the same way. but theres a problem. the background isnt transparant
anymore!!! the background color(magenta aka 255,0,255) shows up now on my
screen!! not only does it show up, but it almost looks like bits and pieces
of it are transparant. why is this so? can you only do transparancy with a
.bmp file? how do i make the transparancy work with a .jpg? could someone
please help me!!! thank you very much everyone. BTW here is a piece of my
code, the first half loads the images, and the second half makes them
transparant. maybe the SetColorKey has to change somehow to work with
.jpgs??? thanks for any help!!! i appreciate it

data.back = IMG_Load(“Background.jpg”);
data.player_paddle = IMG_Load(“PlayerPaddle.bmp”);
data.enemy_paddle = IMG_Load(“EnemyPaddle.bmp”);

SDL_SetColorKey(data.player_paddle,
SDL_SRCCOLORKEY,SDL_MapRGB(data.player_paddle->format, 255, 0, 255));
SDL_SetColorKey(data.enemy_paddle,
SDL_SRCCOLORKEY,SDL_MapRGB(data.enemy_paddle->format, 255, 0, 255));_________________________________________________________________
Get a FREE online computer virus scan from McAfee when you click here.
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

[…BMP->JPG…]

everything worked fine! so im all excited, thinking this would
work. i then change all my in game objects(the paddle’s and ball)
from bmps to jpgs in the same way. but theres a problem. the
background isnt transparant anymore!!! the background color(magenta
aka 255,0,255) shows up now on my screen!! not only does it show
up, but it almost looks like bits and pieces of it are transparant.
why is this so?

What you’re seeing is actually not exactly 255, 0, 255, but various
approximations of that color. JPG is a destructive compression
format, so you should never use it if you need totally undistorted
images or exact colors.

can you only do transparancy with a .bmp file?

No, any format with non-destructive compression should work fine. I’d
suggest PNG, which also happens to be about the only format that has
both serious non-destructive compression and alpha channel support.
(You can use alpha for transparency if you want antialiazing and/or
transparency effects.)

how
do i make the transparancy work with a .jpg?

You can’t do that reliably. You could use a custom chromakey filter
or something, to find and clean up the areas that should be
transparent, but I’d say it’s a waste of time unless you really
have to do this with a destructive format such as JPG…

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Friday 27 February 2004 02.34, Graveyard Filla wrote: