Alpha blending, sprites

Hello sdl,

And more questions…

I want to blit pictures with alpha channel. Because there is function for
loading images only for .bmp format I saved my picture in that format, with 32
bits. I’m even know is .bmp supporting alpha channel, but I assumed it does,
because there is 32bit mode (is it?). Then I set alpha mode for blitting:

    SDL_SetAlpha(sprite, SDL_SRCALPHA |SDL_SRCCOLORKEY , 255);

I tried also:

    SDL_SetAlpha(sprite, SDL_SRCALPHA , 255);

But then whole image is visible - alpha is ignored. What is wrong here? bmp
format or wrong alpha setting?

(Only last parameter really works (effects blending))

If .bmp is guilty for that how can I open i.e. .tga format?

Generally speaking what is the best way to improvise sprites (with alpha)?
I mean should I for every frame blit background and then sprites, or should I
save background only of areas that sprites will destroy, and at next frame first
do all repairs and get new backgrounds and then draw sprites or some other way
is better?–
Best regards,
Milan mailto:milan_g at eunet.yu

Hello sdl,

And more questions…

I want to blit pictures with alpha channel. Because there is
function for loading images only for .bmp format I saved my picture
in that format, with 32 bits. I’m even know is .bmp supporting
alpha channel, but I assumed it does, because there is 32bit mode
(is it?).

There might be some recent or unofficial alpha extension to BMP, but
even if there is, I’m quite sure SDL doesn’t support it.

Then I set alpha mode for blitting:

    SDL_SetAlpha(sprite, SDL_SRCALPHA |SDL_SRCCOLORKEY , 255);

I tried also:

    SDL_SetAlpha(sprite, SDL_SRCALPHA , 255);

The latter is what you should use. The colorkey flag is for the
SDL_SetColorKey() call, and you shouldn’t mess with colorkeying
together with alpha channel normally anyway.

But then whole image is visible - alpha is ignored. What is wrong
here? bmp format or wrong alpha setting?

Have you tried loading those images into GIMP, PhotoShop or whatever
you’re using? I suspect that there is no alpha channel. It could be
that the generating application has reduced alpha to colorkey, but
you most probably don’t want that. (1 bit “alpha”…)

(Only last parameter really works (effects blending))

Yeah, that’s the full surface blending feature - and since that
doesn’t mix with alpha channel blending, you obviously do not get an
alpha channel when you load those images.

If .bmp is guilty for that how can I open i.e. .tga format?

TGA should work, but I’d strongly recommend PNG. It does what you
need, and you get serious non-destructive compression as a bonus.

Generally speaking what is the best way to improvise sprites (with
alpha)?

The way you’re trying to do it (with a suitable file format) - or
perhaps via OpenGL, if accelerated OpenGL is an acceptable system
requirement…

I mean should I for every frame blit background and then
sprites, or should I save background only of areas that sprites
will destroy, and at next frame first do all repairs and get new
backgrounds and then draw sprites or some other way is better?

Something in between. Never blit from the screen! You could end up
reading VRAM, which is slow enough that just a few sprites will
render slower than rerendering the whole screen every frame.

By “something in between” I mean remove sprites by redrawing the
background over the old areas, using map + tiles or whatever you’re
using. You could have a look at by Pig “example” (playable game, sort
of), which does exactly this. (See URL in sig; “SDL Examples”.)

//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 Wednesday 01 December 2004 12.22, Milan Golubovic wrote:

Hey Milan,

Check out SDL_Image, it can load alot more kinds of formats, tga, png, jpg,
gif etc.

tga,png,gif support alpha channel i believe so you should use those instead
of bmp (:

http://www.libsdl.org/projects/SDL_image> ----- Original Message -----

From: milan_g@eunet.yu (Milan Golubovic)
To:
Sent: Wednesday, December 01, 2004 3:22 AM
Subject: [SDL] Alpha blending, sprites…

Hello sdl,

And more questions…

I want to blit pictures with alpha channel. Because there is function for
loading images only for .bmp format I saved my picture in that format,
with 32
bits. I’m even know is .bmp supporting alpha channel, but I assumed it
does,
because there is 32bit mode (is it?). Then I set alpha mode for blitting:

    SDL_SetAlpha(sprite, SDL_SRCALPHA |SDL_SRCCOLORKEY , 255);

I tried also:

    SDL_SetAlpha(sprite, SDL_SRCALPHA , 255);

But then whole image is visible - alpha is ignored. What is wrong here?
bmp
format or wrong alpha setting?

(Only last parameter really works (effects blending))

If .bmp is guilty for that how can I open i.e. .tga format?

Generally speaking what is the best way to improvise sprites (with alpha)?
I mean should I for every frame blit background and then sprites, or
should I
save background only of areas that sprites will destroy, and at next frame
first
do all repairs and get new backgrounds and then draw sprites or some other
way
is better?


Best regards,
Milan mailto:milan_g at eunet.yu


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

AFAIK, a 32 bits bmp file doesn’t store an alpha channel, it is only wasting 1
byte per pixel.
Use png or Targa or store your alpha channel in another bmp file…

To verify that your method of blitting is ok, you could also generate (instead
of load) a bitmap with alpha directly in your testing program.

Regards,
William.On Wednesday 01 December 2004 13:22, Milan Golubovic wrote:

Hello sdl,

And more questions…

I want to blit pictures with alpha channel. Because there is function for
loading images only for .bmp format I saved my picture in that format, with
32 bits. I’m even know is .bmp supporting alpha channel, but I assumed it
does, because there is 32bit mode (is it?). Then I set alpha mode for
blitting:
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFBr3+MgZg2O9ZtN5MRAvUuAJ9oGHWKrUZ46RTnYnKjmMzE8RAxNwCfYB21
pUcsO+vawVuYr+wa8DaFNLY=
=FR+E
-----END PGP SIGNATURE-----

Hello Alan,

Thursday, December 2, 2004, 12:48:10 AM, you wrote:

AW> Hey Milan,

AW> Check out SDL_Image, it can load alot more kinds of formats, tga, png, jpg,
AW> gif etc.

AW> tga,png,gif support alpha channel i believe so you should use those instead
AW> of bmp (:

Yep! It works! :slight_smile:
I got problems saving TGA pictures with ALPHA in PhotoShop (simply they don’t have alphe),
but PNG works well. Very nice lib. Thanks!

I wonder why this lib or i.e. SDL Mixer lib are not part of SDL it self?–
Best regards,
Milan mailto:milan_g at eunet.yu