Again, make sure the image you cut is 320 pixels wide and 384 pixels high.
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
ddsd.dwWidth = 320;
ddsd.dwHeight = 384;
hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSOne, NULL);
if (hRet != DD_OK)
return InitFail(hWnd, hRet, szCreateSurfaceFailMsg);
Notice that the dimensions of the surface match the bitmap size, 320×384. Lets load the bitmap onto the surface now, in InitSurfaces():
DDCopyBitmap(g_pDDSOne, hbm, 0, 0, 320, 384);
So g_pDDSOne now points to a surface that holds our bitmap. Oh and one more thing, just declare a const variable to hold the number of columns in the image,
static const int TOTAL_COLS = 5;
Yes, you can go back and count (: Anyways, lets take a look at the UpdateFrame() function now:
static void UpdateFrame(HWND hWnd)
{
static BYTE phase = 0;
HRESULT hRet;
DDBLTFX ddbltfx;
RECT src, dest;
int row = 0, col = 0;
memset(&ddbltfx, 0, sizeof(ddbltfx));
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0;
ddbltfx.dwROP = SRCCOPY;
//the destination rect is in the center of the screen
dest.top = 128;
dest.left = 88;
dest.bottom = 192;
dest.right = 152;
//clear the back buffer (color fill with black)
g_pDDSBack->Blt(&dest, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAITNOTBUSY, &ddbltfx);
//calculate the src rect depending on the value of ‘phase’
row = phase/TOTAL_COLS;
col = phase%TOTAL_COLS;
src.top = 64*row;
src.left = 64*col;
src.bottom = src.top + 64;
src.right = src.left + 64;
while (TRUE)
{
hRet = g_pDDSBack->Blt(&dest, g_pDDSOne, &src, DDBLT_ROP, &ddbltfx);
if (hRet == DD_OK)
break;
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreAll();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
phase = (phase+1)%30;
}
#define TIMER_RATE 80
I took a small video of the rotating spaceship.