Splitting a surface with an alpha channel into tiles

Hello

I’d like to split a surface with an alpha channel (loaded from a .png
file with SDL_image) into tiles, so each tile is in its own surface.
However, this has caused me much trouble. After playing around with
SDL_CreateRGBSurface, SDL_DisplayFormat(Alpha) and SDL_SetAlpha, the
only results I got were either invisible surfaces or surfaces with a
black background instead of transparency.

Could anyone please provide me with an example how to do this correctly
or explain it to me?
It doesn’t sound too difficult, still I’m obviously too stupid for it.

Thank you,
Bernhard

If you want to load a png, I belive you have to use SDL_image
since png’s are not loadable using the standard SDL functions.

Is there a reason you want to load each tile as its own surface?
Or do you not know how to use a tileset that uses one surface?
When blitting you can set the X offset and Y offset, to blit
just one tile, even if it is a whole tileset on the surface.

to all: Would it waste memory loading each tile as a new surface
than loading one surface for the tileset?

— Bernhard Bliem <bernhard.bliem at chello.at> wrote:> Hello

I’d like to split a surface with an alpha channel (loaded from
a .png
file with SDL_image) into tiles, so each tile is in its own
surface.
However, this has caused me much trouble. After playing around
with
SDL_CreateRGBSurface, SDL_DisplayFormat(Alpha) and
SDL_SetAlpha, the
only results I got were either invisible surfaces or surfaces
with a
black background instead of transparency.

Could anyone please provide me with an example how to do this
correctly
or explain it to me?
It doesn’t sound too difficult, still I’m obviously too stupid
for it.

Thank you,
Bernhard


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


Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

jake b wrote:

If you want to load a png, I belive you have to use SDL_image
since png’s are not loadable using the standard SDL functions.

I did write that I’m using SDL_image.

Is there a reason you want to load each tile as its own surface?
Yes. http://twomix.devolution.com/pipermail/sdl/2004-March/060816.html

Or do you not know how to use a tileset that uses one surface?
When blitting you can set the X offset and Y offset, to blit
just one tile, even if it is a whole tileset on the surface.

Due to the resons you can read in David’s archived post and because this
makes handling the stuff within my engine easier, I’d prefer every tile
in its own surface.

to all: Would it waste memory loading each tile as a new surface
than loading one surface for the tileset?

Of course that would need more memory, but it would also be slower
because you’ll have to do clipping every time you blit it.