Loading bitmaps with transparency?

Hello everyone!

I’m in a situation where I can’t use SDL_image. What’s the best way to
load a transparent image?

Thanks! :wink:

Hello !

I’m in a situation where I can’t use SDL_image. What’s the best way to
load a transparent image?

A way would be to convert your images to
your own format and load that from disk.

For only a few and small images that
is okay.

If you need more and larger images you can also use
libPNG to your programm and use them directly in your
code, SDL_image is just a wrapper to make them easier to
use.

CU

Hello !

I’m in a situation where I can’t use SDL_image. What’s the best way to
load a transparent image?

What kind of transparency ? Just something
like transparent or not as with sprites for
example or alpha transparency where you have
a nr. 0-255 how much transp. the pixel should be ?

CU

Yes, like sprites, only one part is shown… On bitmaps, there’s no
blank-pixel, so the background shows white… :-/

I can’t use any of the C++ libraries 'cause I’m on Lua.

Maybe transparency masks, where there’s a separate black-and-white
bitmap with the black areas as the background and white areas as what I
want to show? Would that be best or no?

Thanks! :wink:

Torsten Giebl wrote:> Hello !

I’m in a situation where I can’t use SDL_image. What’s the best way to
load a transparent image?

What kind of transparency ? Just something
like transparent or not as with sprites for
example or alpha transparency where you have
a nr. 0-255 how much transp. the pixel should be ?

CU

You want this:

http://www.libsdl.org/docs/html/sdlsetcolorkey.html

:slight_smile:

-bill!On Sun, Mar 04, 2007 at 02:06:25AM -0800, L-28C wrote:

Yes, like sprites, only one part is shown… On bitmaps, there’s no
blank-pixel, so the background shows white… :-/

I can’t use any of the C++ libraries 'cause I’m on Lua.

Maybe transparency masks, where there’s a separate black-and-white
bitmap with the black areas as the background and white areas as what I
want to show? Would that be best or no?

Oh, nevermind that, I’m sorry, the SDL_LoadBMP() in this Lua distro
loads transparent PNG’s too… Sorry for the trouble! :stuck_out_tongue:

L-28C wrote:> Yes, like sprites, only one part is shown… On bitmaps, there’s no

blank-pixel, so the background shows white… :-/

I can’t use any of the C++ libraries 'cause I’m on Lua.

Maybe transparency masks, where there’s a separate black-and-white
bitmap with the black areas as the background and white areas as what I
want to show? Would that be best or no?

Thanks! :wink:

Torsten Giebl wrote:

Hello !

I’m in a situation where I can’t use SDL_image. What’s the best way to
load a transparent image?

What kind of transparency ? Just something
like transparent or not as with sprites for
example or alpha transparency where you have
a nr. 0-255 how much transp. the pixel should be ?

CU

L-28C wrote:

Oh, nevermind that, I’m sorry, the SDL_LoadBMP() in this Lua distro
loads transparent PNG’s too… Sorry for the trouble! :stuck_out_tongue:

Uh, that’s an over-simplification. It is best to look at working
Lua or C demos or small programs. You can use: (a) a color key, or
(b) an alpha channel. There is a difference. What you need depends
on what you want to do, but I think you will need to dig into the
documentation a bit more.> L-28C wrote:

Yes, like sprites, only one part is shown… On bitmaps, there’s no
blank-pixel, so the background shows white… :-/

I can’t use any of the C++ libraries 'cause I’m on Lua.

Maybe transparency masks, where there’s a separate black-and-white
bitmap with the black areas as the background and white areas as what I
want to show? Would that be best or no?
[snip]


Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

I can’t use any of the C++ libraries 'cause I’m on Lua.

Maybe transparency masks, where there’s a separate black-and-white
bitmap with the black areas as the background and white areas as what I
want to show? Would that be best or no?

(You found you’ve got alpha channels in PNG files in the Lua
distribution, but for the record here…) what you’re describing is
called a “Color Key” … pick some color in the bitmap you don’t need
(like, bright purple) and tell SDL that whenever it sees that color,
don’t draw the pixel…if all you want to do is mask out pixels so your
sprite isn’t a rectangle (and is instead shaped like, say, Mario),
that’s what you want, since it’s faster than using an alpha channel.

If you want to have some pixels blend with whatever’s behind it instead
of overwriting it (like, the slightly-tinted window in a door sprite),
you need the alpha channel.

If you just want the whole sprite to blend with the background (like
something fading in or out completely), you can use “per-surface alpha”.

Only the second option would need a .png … the rest are faster and can
be done with SDL directly by passing it simple integer values and not
byte arrays, and thus should be usable from Lua.

–ryan.