Alfa chanel problem

Hi, i have a problem loading some sprites.

I have a function that loads an image strip, break it in frames and
save it to an array. Basicaly i need to create an image on the fly for
each frame with
(info is a struct with the width and height of each frame to cut the
strip)

SDL_Surface *frame, *strip;
strip = SDL_Load(“myfile.png”);

frame = SDL_CreateRGBSurface(SDL_HWSURFACE||SDL_SRCALPHA, info->width,
info->height, 32, strip->format->Rmask, strip->format->Gmask,
strip->format->Bmask, strip->format->Amask);

then when i blit a frame to the screen it doesn’t apear.
the only way i find to effectively draw to the screen is if i use a
SDL_DisplayFormat() call, but i lose the alfa chanel.

This only happens if the file has an alfa chanel and if a go through
the frame surface, not if i blit all the strip at once.

Any suggestion please ??

Losky

El 2003.08.06 14:00, Ochendrowitsch Pablo escribi?:

frame = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, …

Sorry, this was a type error in the mail, not in the code.

Use SDL_DisplayFormatAlpha(), then.

Lic. Gabriel Gambetta
ARTech - GeneXus Development Team
ggambett at artech.com.uy> ----- Original Message -----

From: Ochendrowitsch Pablo [mailto:losky@thered.com.ar]
Sent: Mi?rcoles, 06 de Agosto de 2003 02:00 p.m.
To: Lista SDL
Subject: [SDL] alfa chanel problem

Hi, i have a problem loading some sprites.

I have a function that loads an image strip, break it in frames and
save it to an array. Basicaly i need to create an image on the fly for
each frame with
(info is a struct with the width and height of each frame to cut the
strip)

SDL_Surface *frame, *strip;
strip = SDL_Load(“myfile.png”);

frame = SDL_CreateRGBSurface(SDL_HWSURFACE||SDL_SRCALPHA, info->width,
info->height, 32, strip->format->Rmask, strip->format->Gmask,
strip->format->Bmask, strip->format->Amask);

then when i blit a frame to the screen it doesn’t apear.
the only way i find to effectively draw to the screen is if i use a
SDL_DisplayFormat() call, but i lose the alfa chanel.

This only happens if the file has an alfa chanel and if a go through
the frame surface, not if i blit all the strip at once.

Any suggestion please ??

Losky


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

You could try SDL_DisplayFormatAlpha
(http://sdldoc.csn.ul.ie/sdldisplayformatalpha.php ) to convert the
surface, that should keep the alpha channel.

It might not solve the problem, though. When you’re creating the new
smaller surfaces and blitting parts of the strip onto them, SDL_Blit is
probably merging the alpha values of the two surfaces together.
Effectively, it’s rendering your strip image onto the frame image,
rather than copying it.

Maybe someone else can confirm this?

What you probably need to do is create the surfaces, lock both of them,
and actually do a byte for byte copy from one surface->pixels to the
other. You should be able to do it pretty easily by using memcpy and
some simple loops.

That way the alpha values will migrate intact, rather than being mixed
with the destination surface.On Wed, 2003-08-06 at 13:00, Ochendrowitsch Pablo wrote:

Hi, i have a problem loading some sprites.

I have a function that loads an image strip, break it in frames and
save it to an array. Basicaly i need to create an image on the fly for
each frame with
(info is a struct with the width and height of each frame to cut the
strip)

SDL_Surface *frame, *strip;
strip = SDL_Load(“myfile.png”);

frame = SDL_CreateRGBSurface(SDL_HWSURFACE||SDL_SRCALPHA, info->width,
info->height, 32, strip->format->Rmask, strip->format->Gmask,
strip->format->Bmask, strip->format->Amask);

then when i blit a frame to the screen it doesn’t apear.
the only way i find to effectively draw to the screen is if i use a
SDL_DisplayFormat() call, but i lose the alfa chanel.

This only happens if the file has an alfa chanel and if a go through
the frame surface, not if i blit all the strip at once.

Any suggestion please ??

Losky


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


Jimmy <@Jimmy>
Jimmy’s World.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030806/fe26804f/attachment.pgp

El 2003.08.06 14:48, Jimmy escribi?:

You could try SDL_DisplayFormatAlpha
(http://sdldoc.csn.ul.ie/sdldisplayformatalpha.php ) to convert the
surface, that should keep the alpha channel.

It might not solve the problem, though. When you’re creating the new
smaller surfaces and blitting parts of the strip onto them, SDL_Blit
is
probably merging the alpha values of the two surfaces together.
Effectively, it’s rendering your strip image onto the frame image,
rather than copying it.

Maybe someone else can confirm this?

Now i can, i prove it and y could see my sprite only if i filled the
surface with an 100% opaque color

What you probably need to do is create the surfaces, lock both of
them,
and actually do a byte for byte copy from one surface->pixels to the
other. You should be able to do it pretty easily by using memcpy and
some simple loops.

That way the alpha values will migrate intact, rather than being mixed
with the destination surface.

ok thanks i solved it and if any have the same problem,
here is my code

#include <SDL/SDL.h>
#include <string.h>

void SDL_CopySurface (SDL_Surface *source, SDL_Rect *src,
SDL_Surface *destiny, SDL_Rect *dest)
{
int i;
int s_offset, d_offset;
Uint8 *s_point, *d_point;

SDL_LockSurface(source);
SDL_LockSurface(destiny);

s_point = (Uint8 *) source->pixels;
d_point = (Uint8 *) destiny->pixels;

for (i = 0; i < src->h; i++){	// Contador de fila

   s_offset=(((src->y)+i)*(source->pitch)+
             ((src->x)*(source->format->BytesPerPixel)));
   d_offset=(((dest->y)+i)*(destiny->pitch)+
             ((src->x)*(source->format->BytesPerPixel)));

   memmove ( & d_point[ d_offset], & s_point[s_offset],
	(src->w)*(source->format->BytesPerPixel));

}

SDL_UnlockSurface(source);
SDL_UnlockSurface(destiny);

}

Good stuff.
You might want to put a check into that method to make sure that the
masks are the same before you do the copy. This would have some very
interesting effects if the two surfaces didn’t have exactly the same
masks & bytes/bits per pixel.On Wed, 2003-08-06 at 21:02, Ochendrowitsch Pablo wrote:

El 2003.08.06 14:48, Jimmy escribi?:

You could try SDL_DisplayFormatAlpha
(http://sdldoc.csn.ul.ie/sdldisplayformatalpha.php ) to convert the
surface, that should keep the alpha channel.

It might not solve the problem, though. When you’re creating the new
smaller surfaces and blitting parts of the strip onto them, SDL_Blit
is
probably merging the alpha values of the two surfaces together.
Effectively, it’s rendering your strip image onto the frame image,
rather than copying it.

Maybe someone else can confirm this?

Now i can, i prove it and y could see my sprite only if i filled the
surface with an 100% opaque color

What you probably need to do is create the surfaces, lock both of
them,
and actually do a byte for byte copy from one surface->pixels to the
other. You should be able to do it pretty easily by using memcpy and
some simple loops.

That way the alpha values will migrate intact, rather than being mixed
with the destination surface.

ok thanks i solved it and if any have the same problem,
here is my code

#include <SDL/SDL.h>
#include <string.h>

void SDL_CopySurface (SDL_Surface *source, SDL_Rect *src,
SDL_Surface *destiny, SDL_Rect *dest)
{
int i;
int s_offset, d_offset;
Uint8 *s_point, *d_point;

SDL_LockSurface(source);
SDL_LockSurface(destiny);

s_point = (Uint8 *) source->pixels;
d_point = (Uint8 *) destiny->pixels;

for (i = 0; i < src->h; i++){	// Contador de fila

   s_offset=(((src->y)+i)*(source->pitch)+
             ((src->x)*(source->format->BytesPerPixel)));
   d_offset=(((dest->y)+i)*(destiny->pitch)+
             ((src->x)*(source->format->BytesPerPixel)));

   memmove ( & d_point[ d_offset], & s_point[s_offset],
  (src->w)*(source->format->BytesPerPixel));

}

SDL_UnlockSurface(source);
SDL_UnlockSurface(destiny);

}


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


Jimmy <@Jimmy>
Jimmy’s World
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030806/3e9d3f98/attachment.pgp