memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize=sizeof(ddsd);
//鎖定主顯示表面
if (FAILED(lpddsprimary->Lock(NULL, &ddsd,
DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,
NULL)))
return(0);
int lpitch32 = (int)(ddsd.lPitch >> 2);
UINT *video_buffer = (UINT *)ddsd.lpSurface;
for (int index=0; index < 1000; index++)
{
// select random position and color for 640x480x32
int red = rand()%256;
int green = rand()%256;
int blue = rand()%256;
int x = rand()%640;
int y = rand()%480;
UINT pixel = ((blue) + ((green) << 8) + ((red) << 16) + ((0) << 24));
//寫色
video_buffer[x + y*lpitch32] = pixel;
} // end for index
//解鎖主顯示表面
if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);
return(1);
} // end Game_Main