PDA

View Full Version : Blitting modes in SDL?


Taxxodium
2003.10.27, 07:11 AM
Are there such things as blitting modes in SDL? A bit like CopyBits has? With modes I mean things like srcAdd or srcCopy etc...

I wanna use SDL but the problem I'm having is that when I use graphics that have a blurred edge (like a glow effect) the transparecy doesn't get applied well.

Does anyone have any tips on how to solve this.

Thanks in advance.

sealfin
2003.10.27, 12:39 PM
In the docs, the entry for SDL_SetAlpha (if I recall the right function - just search on alpha) has a list of the effects of alpha-alpha, alpha-opaque, ad nauseum blits...

If you mean you want a surface which has a per-pixel alpha channel (similar to icons in OS X) you'll have to code a function to call SDL_DisplayFormatAlpha, then plot the contents of the alpha-channel by hand. Or if I'm able to locate it, I could post the source to mine...

sealfin
2003.10.27, 12:43 PM
Not the most perfect fragment of code, but it works quite well... by the way, assumes your call to SDL_SetVideoMode passes 32 as the depth - if not, you'll end up with a rather odd image.SDL_Surface *InputImageWithAlphaMask( const char *imagePath,
const char *maskPath )
{
SDL_Surface *imageSurface,
*maskSurface;
Uint16 x, y;
Uint8 keptR, keptG, keptB, keptA,
discardR, discardG, discardB, discardA;
Uint32 *imagePixels,
*maskPixels;

if(( imageSurface = IMG_Load( imagePath )) == NULL )
{
Fin_LogError( "couldn't input the image '%s'", imagePath );
label_error:
return NULL;
}
if(( maskSurface = IMG_Load( maskPath )) == NULL )
{
Fin_LogError( "couldn't input the mask '%s'", maskPath );
goto label_error;
}
if(( imageSurface->w != maskSurface->w ) || ( imageSurface->h != maskSurface->h ))
{
Fin_LogError( "dimensions of image and mask differ" );
goto label_error;
}


imageSurface = SDL_DisplayFormatAlpha( imageSurface );
maskSurface = SDL_DisplayFormat( maskSurface );
SDL_LockSurface( imageSurface );
SDL_LockSurface( maskSurface );
imagePixels = imageSurface->pixels;
maskPixels = maskSurface->pixels;
for( y = 0;
y < imageSurface->h;
y ++ )
{
for( x = 0;
x < imageSurface->w;
x ++ )
{
SDL_GetRGBA( maskPixels[ Reference_1D_as_2D( maskSurface->w, x, y ) ], maskSurface->format, &keptA, &discardG, &discardB, &discardA );
SDL_GetRGBA( imagePixels[ Reference_1D_as_2D( imageSurface->w, x, y ) ], imageSurface->format, &keptR, &keptG, &keptB, &discardA );
imagePixels[ Reference_1D_as_2D( imageSurface->w, x, y ) ] = SDL_MapRGBA( imageSurface->format, keptR, keptG, keptB, keptA );
}
}
SDL_UnlockSurface( imageSurface );
SDL_UnlockSurface( maskSurface );
return imageSurface;
}
[Later: no, I don't know quite what happened to the tabs.]