Blitting modes in SDL?
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.
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.
"When you dream, there are no rules..."
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...
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...
Mark Bishop
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.
[Later: no, I don't know quite what happened to the tabs.]
Code:
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;
}Mark Bishop
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| SDL Blitting | KidTsunami | 5 | 5,939 |
May 8, 2008 08:17 AM Last Post: leRiCl |
|
| problems blitting a picture to the screen | petr6534 | 4 | 3,563 |
Oct 20, 2004 04:18 PM Last Post: petr6534 |
|
| Switch Between Fullscreen and Windowed Modes - Again... | thaeez | 2 | 2,687 |
Jul 9, 2004 02:49 AM Last Post: thaeez |
|
| switching projection modes | Muffinking | 1 | 1,978 |
Aug 10, 2003 08:34 PM Last Post: OneSadCookie |
|
| alpha textures & blending modes? | arekkusu | 6 | 5,116 |
Nov 7, 2002 03:49 AM Last Post: arekkusu |
|

