Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you clear DirectX surfaces?

87 views
Skip to first unread message

Rainer Weitz

unread,
Jul 28, 1996, 3:00:00 AM7/28/96
to

I've just started programming with the new DirectX2, and this is
also my introduction to Windows programming. I'm trying to do a simple
line drawing program that uses page-flipping. It works fine, but it's
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.
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.
--
=================================================================
Rainer X. Weitz rai...@sj.znet.com
=================================================================

"Oh sweet Information Superhighway, what gem bring you me from
the far reaches of Cyber Space?" -- Crow T. Robot

Samme Ng

unread,
Jul 29, 1996, 3:00:00 AM7/29/96
to

Rainer Weitz wrote:
>
> I've just started programming with the new DirectX2, and this is
> also my introduction to Windows programming. I'm trying to do a simple
> line drawing program that uses page-flipping. It works fine, but it's
> 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.
> 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.

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

The Panther!

unread,
Jul 29, 1996, 3:00:00 AM7/29/96
to

Last time, Samme Ng managed to utter...

>
>Rainer Weitz wrote:
>> 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.

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.


Amit Ghosh

unread,
Jul 30, 1996, 3:00:00 AM7/30/96
to

Rainer Weitz wrote:
>
> I've just started programming with the new DirectX2, and this is
> also my introduction to Windows programming. I'm trying to do a simple
> line drawing program that uses page-flipping. It works fine, but it's
> 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.
> 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.

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

Bryan Dube

unread,
Jul 30, 1996, 3:00:00 AM7/30/96
to



> 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.

Andy James Buchanan

unread,
Jul 31, 1996, 3:00:00 AM7/31/96
to The Panther!

The Panther! wrote:
>
> Last time, Samme Ng managed to utter...
> >
> >Rainer Weitz wrote:
> >> 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.
>
> 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.

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;
}
}

0 new messages