I had a quick search and didn't find any solution to this. Almost posted a whinging post that it looked impossible... then figured out how to do it - clip the dest rectangle, and very importantly, use and adjust the rotation center when top or left clipping is needed.
This is my current clipped blit function:
This is my current clipped blit function:
- Code:
#define CLIP_XMIN 0
#define CLIP_XMAX 240
#define CLIP_YMIN 0
#define CLIP_YMAX 256 // (I've got a big control panel at 256<y<320)
void CTileMap::Blt(RECT *rDst,CGapiSurface *srcSurface,RECT *rSrc,int flags,GDBLTFX *pBltFX)
{
// TODO: Compute optimal dest rect here
// -------------------------------------------------------------------------------
// Position blit relative to the tilemap's scroll offsets
// -------------------------------------------------------------------------------
rDst->left-=scx; rDst->right-=scx;
rDst->top-=scy; rDst->bottom-=scy;
if (flags&(GDBLT_ROTATIONANGLE|GDBLT_ROTATIONSCALE))
{
// For rotated blits, we've got to clip the DESTINATION (and center)
// ----------------------------------------------------------------------------
flags|=GDBLT_ROTATIONCENTER; // Enable the rotation center
pBltFX->rotationCenter.x=(rDst->right-rDst->left)>>1;
pBltFX->rotationCenter.y=(rDst->bottom-rDst->top)>>1;
if (rDst->left<CLIP_XMIN) // Left clip
{
pBltFX->rotationCenter.x+=(rDst->left-CLIP_XMIN);
rDst->left=CLIP_XMIN;
}
if (rDst->top<CLIP_YMIN) // Top clip
{
pBltFX->rotationCenter.y+=(rDst->top-CLIP_YMIN);
rDst->top=CLIP_YMIN;
}
if (rDst->right >CLIP_XMAX) rDst->right=CLIP_XMAX; // Right clip
if (rDst->bottom>CLIP_YMAX) rDst->bottom=CLIP_YMAX; // Bottom clip
// Check if we've actually got something left to draw
// ----------------------------------------------------------------------------
if (rDst->left>=rDst->right || rDst->top>=rDst->bottom) return;
}
else
{
// TODO : Normal source rect clipping on non-rotated blits
// ----------------------------------------------------------------------------
}
// Blit it to the back buffer (pbb)
pbb->Blt(rDst,srcSurface,rSrc,flags,pBltFX);
}