Bachus
2002.09.18, 10:10 AM
So I want to add the ability to draw sprites and tiles translucent. So rather than coming up with my own method, I thought I would just use BlitPixie, since BlitPixie rocks. The only real problem I saw was that my game uses GWorlds (ie, I'm not using SpriteWorld) and BlitPixie doesn't. So I created my own procedure to get the data I needed out of the GWorlds and then call the BlitPixie translucency code. And it almost works. When I copy an entire GWorld to another GWorld it works just fine. But when I try to copy just part of a GWorld to another it fails and draws nothing. I've been fiddling with the code for the past day and I just can't figure out what I'm missing. So if anybody can point out what I'm missing I'd be most appreciative.
void BlitTranslucent16(GWorldPtr srcGW, GWorldPtr destGW, Rect srcRect, Rect dstRect, unsigned short transLevel)
{
unsigned short *src;
unsigned short *dst;
PixMapHandle srcPixMapHandle = GetGWorldPixMap(srcGW);
PixMapHandle dstPixMapHandle = GetGWorldPixMap(destGW);
unsigned long srcRowBytes = (*srcPixMapHandle)->rowBytes & 0x3FFF;
unsigned long dstRowBytes = (*dstPixMapHandle)->rowBytes & 0x3FFF;
UInt16 *srcBaseAddr = (UInt16*)GetPixBaseAddr(srcPixMapHandle);
UInt16 *dstBaseAddr = (UInt16*)GetPixBaseAddr(dstPixMapHandle);
unsigned long source, dest;
unsigned short alpha;
short i, j;
short width, height;
LockPixels(srcPixMapHandle);
LockPixels(dstPixMapHandle);
alpha = ((transLevel >> 8) & 0xFF);
height = srcRect.bottom - srcRect.top;
width = srcRect.right - srcRect.left;
src = ((UInt16*)(srcBaseAddr + (srcRowBytes * srcRect.top) + (srcRect.left << 1)));
dst = ((UInt16*)(dstBaseAddr + (dstRowBytes * dstRect.top) + (dstRect.left << 1)));
srcRowBytes -= (unsigned long)(width << 1);
dstRowBytes -= (unsigned long)(width << 1);
for(j = 0; j < height; j++)
{
for(i = 0; i < width; i++)
{
source = *src++;
dest = *dst;
if(source != 0x0000) // Don't draw black
BLEND_PIXELS_16( source, dest, alpha );
*dst++ = dest;
}
src = (unsigned short *)((char *)src + srcRowBytes);
dst = (unsigned short *)((char *)dst + dstRowBytes);
}
UnlockPixels(dstPixMapHandle);
UnlockPixels(srcPixMapHandle);
}
void BlitTranslucent16(GWorldPtr srcGW, GWorldPtr destGW, Rect srcRect, Rect dstRect, unsigned short transLevel)
{
unsigned short *src;
unsigned short *dst;
PixMapHandle srcPixMapHandle = GetGWorldPixMap(srcGW);
PixMapHandle dstPixMapHandle = GetGWorldPixMap(destGW);
unsigned long srcRowBytes = (*srcPixMapHandle)->rowBytes & 0x3FFF;
unsigned long dstRowBytes = (*dstPixMapHandle)->rowBytes & 0x3FFF;
UInt16 *srcBaseAddr = (UInt16*)GetPixBaseAddr(srcPixMapHandle);
UInt16 *dstBaseAddr = (UInt16*)GetPixBaseAddr(dstPixMapHandle);
unsigned long source, dest;
unsigned short alpha;
short i, j;
short width, height;
LockPixels(srcPixMapHandle);
LockPixels(dstPixMapHandle);
alpha = ((transLevel >> 8) & 0xFF);
height = srcRect.bottom - srcRect.top;
width = srcRect.right - srcRect.left;
src = ((UInt16*)(srcBaseAddr + (srcRowBytes * srcRect.top) + (srcRect.left << 1)));
dst = ((UInt16*)(dstBaseAddr + (dstRowBytes * dstRect.top) + (dstRect.left << 1)));
srcRowBytes -= (unsigned long)(width << 1);
dstRowBytes -= (unsigned long)(width << 1);
for(j = 0; j < height; j++)
{
for(i = 0; i < width; i++)
{
source = *src++;
dest = *dst;
if(source != 0x0000) // Don't draw black
BLEND_PIXELS_16( source, dest, alpha );
*dst++ = dest;
}
src = (unsigned short *)((char *)src + srcRowBytes);
dst = (unsigned short *)((char *)dst + dstRowBytes);
}
UnlockPixels(dstPixMapHandle);
UnlockPixels(srcPixMapHandle);
}