Problems with SDL_BitSurface!

Hello!
First some background. A few years ago I wrote a platform game for the PC.
It was written using C/C++ and assembler for the graphics stuff. Recently
I thought it would be fun to port it to linux and other platforms. I
started to look around for graphic and sound libraries. I ended up with
allegro. The port was straightforward and worked quite well. But…
Allegro seems to have some problems… So I thought about using SDL which
was recommended by a friend.
But such as the subject implies, I have a problem…

I have set up the screen to 320x200 in 16bit color mode. I use a "buffer"
page that I draw to (using SDL_BlitSurface) and once each frame this
buffer is blitted to the video-surface (using SDL_Flip). My problem is
this. I have sprites which I have set the transparant pixel on using
SDL_SetColorKey (to a Pink color). These are then blitted to the buffer
page. But the problem is that the blit isn’t transparant. At least it
doesnA’t look like that on the screen. I get a box around each sprite that
are black (my transparant color is pink (255, 0, 255)).

What’s wrong? Should I set transparancy info for the destination surface
also? Use this “Alpha channel stuff”?

If you need code tell be, I just thought this info should be enough for
experienced SDL users.

Please help.

/ Niklas----------------------------------------------------------------------

Chat with friends online, try MSN Messenger: Click Here

Hello!

I’m sorry. Thought that Hotmail sended in plain text… Well, here it is in
plain text format (hopefully).

First some background. A few years ago I wrote a platform game for the PC.
It was written using C/C++ and assembler for the graphics stuff. Recently I
thought it would be fun to port it to linux and other platforms. I started
to look around for graphic and sound libraries. I ended up with allegro. The
port was straightforward and worked quite well. But… Allegro seems to have
some problems… So I thought about using SDL which was recommended by a
friend.
But such as the subject implies, I have a problem…
I have set up the screen to 320x200 in 16bit color mode. I use a "buffer"
page that I draw to (using SDL_BlitSurface) and once each frame this buffer
is blitted to the video-surface (using SDL_Flip). My problem is this. I have
sprites which I have set the transparant pixel on using SDL_SetColorKey (to
a Pink color). These are then blitted to the buffer page. But the problem is
that the blit isn’t transparant. At least it doesn?t look like that on the
screen. I get a box around each sprite that are black (my transparant color
is pink (255, 0, 255)).

What’s wrong? Should I set transparancy info for the destination surface
also? Use this “Alpha channel stuff”?

If you need code tell be, I just thought this info should be enough for
experienced SDL users.

Please help.

/ Niklas>From: EvilTypeGuy To: Niklas Pettersson Subject: Re: [SDL] Problems with

SDL_BitSurface!!! Date: Tue, 21 May 2002 09:21:32 -0500

Please send your messages in plain text. Otherwise, most of this will only
see this:

On Tue, May 21, 2002 at 04:06:00PM +0200, Niklas Pettersson wrote:


Chat with friends online, try MSN Messenger: http://messenger.msn.com

I have set up the screen to 320x200 in 16bit color mode. I use a "buffer"
page that I draw to
(using SDL_BlitSurface) and once each frame this buffer is blitted to the
video-surface
(using SDL_Flip). My problem is this. I have sprites which I have set the
transparant pixel on
using SDL_SetColorKey (to a Pink color). These are then blitted to the
buffer page.
But the problem is that the blit isn’t transparant. At least it doesn?t
look like that on the screen.
I get a box around each sprite that are black (my transparant color is pink
(255, 0, 255)).
What’s wrong? Should I set transparancy info for the destination surface
also? Use this “Alpha >channel stuff”?

Maybe some more information, place code on net and give link to that.
Shortly, you have bug - but we don’t know where :slight_smile:

        Grzegorz Jaskiewicz

C/C++/PERL/PHP/SQL Programmer

Ok, here is some more info. But first a repetition of the question. I don’t
achieve a transparant blit altough I have set the transparancy color (pink
in my case). Instead I end up with a black box around all sprites.

I Create the surfaces (for sprites, build pages etc) using this function.

SDL_Surface *createSurface(int w, int h)
{
SDL_Surface *temp = 0;
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 16, 0xF800, 0x07E0,
0x001F, 0);
// Should not have alpha-channel.
SDL_SetAlpha(temp, 0, SDL_ALPHA_OPAQUE);
// Should have a transparant pixel
SDL_SetColorKey(temp, SDL_SRCCOLORKEY, TRANSPARANT_COLOR);
return (temp);
}

The TRANSPARANT_COLOR is a value that I got using the “map-rgb” function
(63519 or (r,g,b) = (255, 0, 255)). Resolution is 320x200x16.
Blitting is achieved using the following code:

//
// Set blitting rectangles for the blit
//
SDL_Rect sr, dr;
sr.x = sx;
sr.y = sy;
dr.x = dx;
dr.y = dy;
sr.w = dr.w = w;
sr.h = dr.h = h;

int res = SDL_BlitSurface(source, &sr, dest, &dr);

The sx, sy and so on are given as parameters to the function in which the
above code snipped is resided.

One last thing, the setting of video mode.

SDL_Surface *sp = SDL_SetVideoMode(320, 200, 16, SDL_HWSURFACE | 

SDL_DOUBLEBUF | SDL_FULLSCREEN);

Hope this info is enough.

/ Niklas>From: “Grzegorz Jaskiewicz” Reply-To: sdl at libsdl.org To: Subject: Re: [SDL]

Problems with SDL_BitSurface!!! Date: Tue, 21 May 2002 22:42:50 +0200

I have set up the screen to 320x200 in 16bit color mode. I use a “buffer"
page that I draw to >(using SDL_BlitSurface) and once each frame this
buffer is blitted to the video-surface >(using SDL_Flip). My problem is
this. I have sprites which I have set the transparant pixel on >using
SDL_SetColorKey (to a Pink color). These are then blitted to the buffer
page. >But the problem is that the blit isn’t transparant. At least it
doesn?t look like that on the screen. >I get a box around each sprite that
are black (my transparant color is pink (255, 0, 255)). >What’s wrong?
Should I set transparancy info for the destination surface also? Use this
"Alpha >channel stuff”?

Maybe some more information, place code on net and give link to that.
Shortly, you have bug - but we don’t know where :slight_smile:

Grzegorz Jaskiewicz C/C++/PERL/PHP/SQL Programmer

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


Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.