Problem with Alphachannel with SDL::xxx blitting

  • Thread starter Andreas Romeyke
  • Start date
A

Andreas Romeyke

Hello,

In my script I want to blit PNG-images on the application screen via
the SDL-modules.

The problem is, that the alpha-channel of my PNG-images will be ignored
and drawed as black. My initilization looks like:

my $sdl_flags = SDL_ANYFORMAT | SDL_HWSURFACE | SDL_DOUBLEBUF |
SDL_HWACCEL | SDL_ASYNCBLIT;

# define Application Window/Screen
my $app = SDL::App->new(
-title=> "Moving Balls",
-depth => 32, # color depth
-width => 800,
-height => 600,
-resizeable => 1,
-doublebuffer=>1,
-flags => $sdl_flags,
);

But the problem occurs also if I leave the flags and color depth empty.

I used the article on Ars Technica written by Andy Bakun
(http://arstechnica.com/guides/tweaks/games-perl.ars) and another onbe
written by Michael Schilli
(http://perlmeister.com/snapshots/200710/index.html) as base
documentation, because the core documentaion shipped with the
SDL-Module is, erm, unusable.

The blitting method of my sprite-objects looks like:

sub _draw {
my $self=shift;
my $app=shift;
my $image=shift;
my $pos = $self->get_position();
my $x = $pos->[0];
my $y = $pos->[1];
my $rect=$self->{rect};
my $old_rect = SDL::Rect->new(
-height => $rect->height,
-width => $rect->width,
-x => $rect->x,
-y => $rect->y,
);
$rect->x($pos->[0]);
$rect->y($pos->[1]);
$self->{rect}=$rect;
$app->fill($old_rect,
$bg_color);
$image->blit(0,$app,$rect);
$app->update($old_rect, $rect);
}

and the images are initialized in sprite-objects constructor by calling:

sub _init_image {
my $self=shift;
my $img = shift;
my $image = SDL::Surface->new(
-name=> $img,
-depth => 32,
);
return $image;
}

The blitting works as expected, but the pixels of transparency on
given PNG are drawed black.

$> file *.png

reports that:

flower.png: PNG image data, 48 x 48, 8-bit/color RGBA, non-interlaced
logo.png: PNG image data, 28 x 22, 8-bit/color RGBA, non-interlaced
smiley.png: PNG image data, 48 x 48, 8-bit/color RGBA, non-interlaced
thing.png: PNG image data, 48 x 48, 8-bit/color RGBA, non-interlaced

Please could you help me where I am wrong and what kind of
SDL-needs I have not used?

I am working under Debian Etch with SDL version:

libsdl-perl: 1.20.3dfsg-1

perl -e 'use SDL; print $SDL::VERSION;' reports "1.20.3".

Any hints?

Bye Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top