"Oh sweet Information Superhighway, what gem bring you me from
the far reaches of Cyber Space?" -- Crow T. Robot
Hello,
You should use the Lock member function to get the surface's pointer.
Then you can clear the surface by memset(surface_pointer, 0, size).
Also, you can write pixel to the surface by writing directly to the
surface's pointer. By using the Lock function, it just like writing
image, pixel in 0xa0000 as the surface pointer.
For detail, please look at the Lock member function.
Best Regards,
Samme Ng
sa...@hk.super.net
I thought there was one. Should be a fill with color routine there someplace.
>Hello,
> You should use the Lock member function to get the surface's pointer.
>Then you can clear the surface by memset(surface_pointer, 0, size).
Or use the clear function itself (I don't know the name off-hand) which will
provide an asynchronous clear on a hardware accelerated surface. Quite a bit
faster, seeing that as long as the surface you're clearing isn't being used
at the time, you can do other things while it clears.
JH
[-------------------+-------------------------+------------------------------]
Jason Hughes |Rush, Jimi, Eric Johnson,|How beautiful is the snowshine
Software Engineer |Ian Moore, Austin, TX.___| in your eyes, so directly
Origin Systems, Inc. ~~~~~~~~~~~~~~~~~~'current from the static in your brain.
You can use the hardware blitter to clear a surface under DirectX2. The
following
is a function, that shows how to do this.
HRESULT DX2ColorFill( LPDIRECTDRAWSURFACE lpBuffer, DWORD dwFillColor )
{
HRESULT ddrval;
DDBLTFX ddBltFx;
// make sure, that the surface isn't lost (if possible, implement
// this at a higher level in your program).
if( lpBuffer->IsLost() == DDERR_SURFACELOST )
{
ddrval == lpBuffer->Restore();
if( ddrval != DD_OK )
return ddrval;
}
// setup the DDBLTFX structure
memset( &ddBltFx, 0, sizeof( DDBLTFX ) );
ddBltFx.dwSize = sizeof( DDBLTFX );
ddBltFx.dwFillColor = dwColor;
// use the blitter to clear the surface
ddrval = lpBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL|DDBLT_WAIT,
&ddBltFx );
if( ddrval == DD_OK )
return ddrval;
}
To write directly to the surface, you have to use the Lock/Unlock
methods.
(see the help file for more informations).
Hope this helps.
--
Amit Ghosh
e-mail : mailto:amit....@hamburg.netsurf.de
> painfully slow. I couldn't find any calls
to clear the back-buffer
> surface, so I'm blitting a bitmap into it
to clear it. There has to be
> some way that is
faster.
Yes, look at the Blt() routine, you can fill in the DDBLTFX structure to perform a color fill, with the color fill you can then clear the screen with any color ( FAST too)
> Also, is there any
way to write pixels directly to a surface?
> I've played
Doom95, and I'm certain they're not using Windows line-draw
>
routines.
Yes, you can access pixels directly by locking the
surface. When you lock a surface you get a pointer back which
represents video memory. Unfortunately you need to know what color
depth your in if you want ot set or get a pixel, and you need to know how
the color information is stored.
Example: 640 x 480 x 256
(Also in CPP )
DDSURFACEDESC ddsd;
lpSurface->Lock (
NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR
);
((BYTE*)ddsd.lpSuface)[y*ddsd.lPitch+x] =
255;
lpSurface->Unlock( ddsd.lpSurface );
This code will
set the pixel at (x,y) to the color specified in palette index 255.
Some of the sample code does pixel manipulation also.
Try This... (It's in C - sorry :-( )
////////////////////////////////////////////////////////////////////////////////
PRIVATE void DDClearSurface( IDirectDrawSurface* pSurface )
{
HRESULT ddrval;
DDBLTFX ddbltfx;
ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
ddbltfx.dwSize = sizeof( ddbltfx );
ddbltfx.dwFillColor = PALETTEINDEX(0);
while( 1 )
{
ddrval = IDirectDrawSurface_Blt(
pSurface, // Dest Surface
NULL, // lpDestRect
NULL, // lpDDSrcSurface
NULL, // lpSrcRect
DDBLT_COLORFILL, // dwFlags (DDBLT_WAIT)
&ddbltfx // lpDDBltFx
);
if ( ddrval == DD_OK ) return;
if ( ddrval == DDERR_SURFACELOST )
{
if( !DDRestoreSurfaces() ) return;
}
if ( ddrval != DDERR_WASSTILLDRAWING ) return;
}
}