Original Post
Ok the code:
void FadeOut565(LPDIRECTDRAWSURFACE7 _lpdds, RECT *_rect, float _pct)
{
DDSURFACEDESC2 ddsd; // surface description struct
USHORT* buffer; // pointer to surface memory
USHORT color; // holds color valu of pixel
UCHAR r=0, g=0, b=0; // r/g/b components of pixel
DWORD pitch; // memory pitch
// init ddsd struct
INIT_DX_STRUCT(ddsd);
// lock surface
_lpdds->Lock(_rect, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, 0);
// get memory ptr
buffer = (USHORT*)ddsd.lpSurface;
// get pitch (ddsd.lPitch is in bytes)
pitch = ddsd.lPitch/2;
// adjust the pointer
buffer -= _rect->left;
// go through every line
for(int y=_rect->top; y<_rect->bottom; y++)
{
// go through every pixel
for(int x=_rect->left; x<_rect->right; x++)
{
// get color value
color = buffer[x];
// extract the components
r = (color & 0xF800) >> 11;
g = (color & 0x07E0) >> 5;
b = (color & 0x001F);
// recalculate the values
r = (UCHAR)((float)r*_pct);
g = (UCHAR)((float)g*_pct);
b = (UCHAR)((float)b*_pct);
// write new pixel on surface
buffer[x] = RGB_16BIT565(r, g, b);
}
// advance pointer
buffer += pitch;
}
// unlock the surface
_lpdds->Unlock(_rect);
} // end of FadeOut565
This function is supposed to fade to black. But I only get 1FPS when it is performed? Is the code sh** or what else?
2nd question: When I blit a single 640*480 surface on the primary I only get about 45FPS. Is this normal too?