How do I clear a ddraw surface?

How do I clear a ddraw surface?

Post by JR » Sun, 17 May 1998 04:00:00



How do I fill a ddraw surface with a color? (maybe with memset()?)

 
 
 

How do I clear a ddraw surface?

Post by Klaus Hartman » Sun, 17 May 1998 04:00:00



Quote:>How do I fill a ddraw surface with a color? (maybe with memset()?)

If your DDraw surface is in display-memory, then you should use
IDirectDrawSurface::Blt() to fill the whole surface or a rectangle
on that surface.

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

 
 
 

How do I clear a ddraw surface?

Post by MightyMous » Mon, 18 May 1998 04:00:00


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;

2. Don't read this message!

3. DDraw Layers and surfaces - Difference ?

4. Mercury/32 + NDS

5. DDraw and D3D: Creating surfaces ?

6. GVP/Micron conflict?

7. Releasing DDraw flipping surfaces

8. Test - please ignore

9. DDraw multiple surfaces

10. DDraw blit to primary surface possible?

11. DDraw, surfaces & tile-engin.Could you help ?

12. DirectX[DDRAW] surfaces