Transparency

Stefan Viljoen wrote:

Hi all,

Given this code:

I don’t know what that line does, but it’s definitely wrong.
See the SDL_SetAlpha manpage for more info :
http://segfault.lnet.lut.fi/huru/opengl/sdl/man3/SDL_SetAlpha.3.html

Thanks Stephane

SDL_SetColorKey(buttons[OK_BUT_PRESSED],SDL_SRCCOLORKEY,
SDL_MapRGB(buttons[OK_BUT_PRESSED]->format,0,0,0));

SDL_BlitSurface(buttons[OK_BUT_PRESSED],NULL,surface,&dstrect);

SDL_UpdateRect(surface,0,0,0,0);

//End code

Can anybody tell me WHY black pixels still do not get masked out? Both

and buttons[OK_BUT_PRESSED] is loaded from a .JPEG file, which has its
transparent areas set to RGB8 0,0,0 using the GIMP.

It might also happen that the jpeg compression loses "perfectly black"
pixels in favor of “almost black” pixels. Usually you can’t see the
difference, but SDL will.

Darn - what file format can I use to store graphics, except JPG, that will not
"lose" certain colors? JPEG compresses nicely, but if it does this it
obviously cannot be used for sprites. TGA? BMP? What would be best?
I think you might have hit it on the nose here. Anybody else got any ideas?

Any ideas anyone? Pointers to where I can get example code showing how to
implement totally transparent pixels in a source surface?

It depends on what you want. Do you want both translucency and
colorkeying ? Looking at your message, it seems not. So you shouldn’t
use both SDL_SetAlpha and SDL_SetColorKey at the same time. Try removing
the SDL_SetAlpha call.

Hmm - did remove the setalpha call - still does not take the “black” pixels
out. On the first question, no I do not want translucency - just transparency
in certain areas with “black” pixels.

Anyway, thanks Stephane!

I appreciate it

Regards,From: stephane.marchesin@wanadoo.fr (Stephane Marchesin)


Stefan Viljoen
F/EMS Dispatcher
Potchefstroom Public Safety Dept.
Republic of South Africa
http://home.intekom.com/rylan/

“We want you to be soldiers - deadly as long as you have one leg or one arm
and you are still alive.”

  • R. A. H. in Starship Troopers

[…]

It might also happen that the jpeg compression loses “perfectly
black” pixels in favor of “almost black” pixels. Usually you
can’t see the difference, but SDL will.

Darn - what file format can I use to store graphics, except JPG,
that will not “lose” certain colors? JPEG compresses nicely, but if
it does this it obviously cannot be used for sprites.

I dunno about “nicely”, but it can be used for sprites if you roll
your own colorkey “cleaner”, with some fuzzyness factor. I added that
to Kobo Deluxe after getting tired of correcting the graphics after
some rounding error in GIMP changed the colorkey from 0xff0000 to
0xfe0000.

That said, I would not recommend jpeg for sprites.

TGA?

Yes, and that also supports alpha channels. (That’s why many 3D games
use it.) However, it doesn’t support compression, so it’s not a great
choice if you install plain files. You can get away with it if you’re
running dirtly from compressed archives, though, like the .pk3 (zip)
files used by Q3 based games, for example.

BMP?

Like TGA (no [widely supported] compression), but it doesn’t support
alpha…

What would be best?

I would strongly recommend PNG. It’s supported by most serious
applications, it’s got efficient non-destructive compression, and it
supports alpha channels.

I think you might have hit it on the nose here.
Anybody else got any ideas?

Any ideas anyone? Pointers to where I can get example code
showing how to implement totally transparent pixels in a source
surface?

It depends on what you want. Do you want both translucency and
colorkeying ? Looking at your message, it seems not. So you
shouldn’t use both SDL_SetAlpha and SDL_SetColorKey at the same
time. Try removing the SDL_SetAlpha call.

Hmm - did remove the setalpha call - still does not take the
"black" pixels out.

As expected. Unless you set a non-opaque full surface alpha (the last
argument), it should have no effect, unless there actually is an
alpha channel - and a jpg can’t have one.

//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 Monday 10 November 2003 20.30, Stefan Viljoen wrote: