How do I fill a ddraw surface with a color? (maybe with memset()?)
If your DDraw surface is in display-memory, then you should useQuote:>How do I fill a ddraw surface with a color? (maybe with memset()?)
DDBLTFX ddbltFX;
ZeroMemory(&ddbltFX,sizeof(ddbltFX));
ddbltFX.dwSize=sizeof(ddbltFX);
ddbltFX.dwFillColor = your fill-color
lpDDS->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&ddbltFX);
If your DDraw surface is in system-memory, then you should use
memset(), because it is faster than Blt.
Niki
void EraseSurface(LPDIRECTDRAWSURFACE lpDDSurfPtr)
{
DDBLTFX ddbltfx;
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0;
HRESULT ddrval;
while(1)
{
ddrval = lpDDSurfPtr->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
if(ddrval == DD_OK)
break;
if(ddrval == DDERR_SURFACELOST)
{
ddrval = restoreSurfaces();
if(ddrval != DD_OK)
return;
}
if(ddrval != DDERR_WASSTILLDRAWING)
return;
}
Quote:}
Quote:> How do I fill a ddraw surface with a color? (maybe with memset()?)
1. DDraw & clearing the back buffer HELP
Can anybody tell me why this does not work:
view.RenderView(player);
pPrimarySurface->Flip(NULL, DDFLIP_WAIT);
ClearSurface(pBackBuffer);
While this does:
view.RenderView(player);
pPrimarySurface->Flip(NULL, DDFLIP_WAIT);
DDBLTFX ddbltfx;
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0;
pBackBuffer->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&ddbltfx);
The code for ClearSurface follows, which seems to work normally otherwise.
Thanks,
-Perry
BOOL ClearSurface(LPDIRECTDRAWSURFACE pSurface)
{
DDSURFACEDESC ddSurfaceDesc;
BOOL success = FALSE;
HRESULT result;
memset(&ddSurfaceDesc,0,sizeof(DDSURFACEDESC));
ddSurfaceDesc.dwSize = sizeof(DDSURFACEDESC);
BOOL exitLoop = FALSE;
do
{
result = pSurface->Lock(NULL,&ddSurfaceDesc,
DDLOCK_SURFACEMEMORYPTR, NULL);
if (result==DDERR_SURFACELOST)
pPrimarySurface->Restore();
else if (result!=DDERR_WASSTILLDRAWING)
exitLoop=TRUE;
}while (!exitLoop);
if (result==DD_OK)
{
UINT surfaceWidth = ddSurfaceDesc.lPitch;
UINT surfaceHeight= ddSurfaceDesc.dwHeight;
char *buf = (char *)ddSurfaceDesc.lpSurface;
memset(buf,0,surfaceWidth * surfaceHeight);
pSurface->Unlock(ddSurfaceDesc.lpSurface);
success = TRUE;
}
return success;
3. DDraw Layers and surfaces - Difference ?
5. DDraw and D3D: Creating surfaces ?
7. Releasing DDraw flipping surfaces
10. DDraw blit to primary surface possible?
11. DDraw, surfaces & tile-engin.Could you help ?