[SDL] Bliting with alpha channel reloaded

Gabriel Gambetta mystml at adinet.com.uy
Mon Mar 13 21:38:35 PST 2006


> As a workaround I've spitted master image to individual sprites and I use
> IMG_Load instead of SDL_CreateSurface and SDL_BlitSurface. But this solution
> is bit awkward (it was copy-paste hell in a gimp^_^ and still I don't know
> if it works with that stain-thing)

In that case you should remove the SDL_SRCALPHA flag, blit, and restore
the SDL_SRCALPHA flag. I think that does what you want to do. In fact I
have that function already :

static void __copyPixels (SDL_Surface* pSrc, SDL_Surface* pDst, int nX,
int nY, int nW, int nH, int nDX, int nDY)
{
	int nOrigFlag = pSrc->flags;
	int nOrigAlpha = pSrc->format->alpha;
	int nOrigCK = pSrc->format->colorkey;

	SDL_SetAlpha(pSrc, 0, 255);
	SDL_SetColorKey(pSrc, 0, 0);

	SDL_Rect pSrcRect;
	pSrcRect.x = nX;
	pSrcRect.y = nY;
	pSrcRect.w = nW;
	pSrcRect.h = nH;

	SDL_Rect pDstRect;
	pDstRect.x = nDX;
	pDstRect.y = nDY;

	SDL_BlitSurface(pSrc, &pSrcRect, pDst, &pDstRect);

	if (nOrigFlag & SDL_SRCALPHA)
		SDL_SetAlpha(pSrc, SDL_SRCALPHA, nOrigAlpha);

	if (nOrigFlag & SDL_SRCCOLORKEY)
		SDL_SetColorKey(pSrc, SDL_SRCCOLORKEY, nOrigCK);
}

        --Gabriel


________________________________________________________________________
Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com





More information about the SDL mailing list