Skip to main content
gamedev.net
🔒 Locked

SDL alpha blitting

Started by programering Feb 19, 2003 at 2:36 AM 4 replies 800+ views
Original Post
programering
programering
I can't get the alpha blitting to work. SDL_Surface *video_screen; video_screen = SDL_SetVideoMode(300,300,32,SDL_ANYFORMAT); SDL_Surface *picture; picture = SDL_LoadBMP("pict.bmp"); SDL_SetAlpha(picture, SDL_SRCALPHA, 100); picture = SDL_DisplayFormatAlpha(picture); SDL_BlitSurface(picture,{0,0},video_screen,{0,0,30,30}); I can't quite remember how I wrote it, but I am sure it was right. Does it have some´thing to do with how I initialize the *video_screen with SDL_SetVideoMode( ... , ... , ... , here in the flags field); ? Can someone correct me here? Anton Karlsson Klingis Entertainment Games with silly humor [edited by - programering on February 26, 2003 3:41:01 AM]
yspotua
yspotua
To enable aplha blitting in SDL you need to use SDL_SetColorKey. Here is the descripion, taken directly from the documentation. You might consider reading the docs; they are pretty straight forward:

int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);

Description

Sets the color key (transparent pixel) in a blittable surface and enables or disables RLE blit acceleration.

RLE acceleration can substantially speed up blitting of images with large horizontal runs of transparent pixels (i.e., pixels that match the key value). The key must be of the same pixel format as the surface, SDL_MapRGB is often useful for obtaining an acceptable value.

If flag is SDL_SRCCOLORKEY then key is the transparent pixel value in the source image of a blit.

If flag is OR''d with SDL_RLEACCEL then the surface will be draw using RLE acceleration when drawn with SDL_BlitSurface. The surface will actually be encoded for RLE acceleration the first time SDL_BlitSurface or SDL_DisplayFormat is called on the surface.

If flag is 0, this function clears any current color key.
Return Value

This function returns 0, or -1 if there was an error.
programering
programering
I meant alpha blitting as a shadow.
For example if *video_screen is a black background,
then the *picture surface when blitted to *video_screen,
it will be drawn half transparent to the screen (so you can see the picture, but faded to black a bit.

Anton Karlsson
Klingis Entertainment
Games with silly humor
Xanth
Xanth
Maybe...


SDL_Surface *video_screen;
video_screen = SDL_SetVideoMode(300,300,32,SDL_ANYFORMAT);

SDL_Surface *picture;
picture = SDL_LoadBMP("pict.bmp");

SDL_SetAlpha(picture, SDL_SRCALPHA , 100);
SDL_BlitSurface(picture,{0,0},video_screen,{0,0,30,30});


"I thought Genius lived in bottles..." - Patrick Star
programering
programering
I have tried everything but it won't work.
But I will try SDL_ANYFORMAT in SDL_SetVideoMode(...) and
removing SDL_DisplayFormatAlpha(...)

Anton Karlsson
Klingis Entertainment
Games with silly humor

[edited by - programering on February 20, 2003 3:01:13 AM]
programering
programering
It worked!

SDL_DisplayFormatAlpha(...) was the problem, and maybe, I don''t know, maybe it was the SDL_ANYFORMAT in SDL_SetVideoMode(...) flags.

Anton Karlsson
Klingis Entertainment
Games with silly humor

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.