How To Clear the z-buffer in Direct3D Retained Mode

Last reviewed: September 5, 1997
Article ID: Q152668
4.00 WINDOWS kbrpg kbhowto

The information in this article applies to:

  • Microsoft DirectX 2 Software Development Kit (SDK), for Windows 95

SUMMARY

The IDirect3DRMViewport::Clear() function will clear a Retained Mode viewport's z-buffer and target rendering surface. You cannot direct this function to clear the z-buffer only. If you need to clear the z-buffer without calling IDirect3DRMViewport::Clear(), then you will need to extract the immediate mode viewport from the retained mode viewport and use the low level clear functions in the immediate mode API to clear the z-buffer only.

MORE INFORMATION

A set of normal Retained Mode rendering instructions may look like the following:

   scene->Move(D3DVALUE(1.0));
   view->Clear();
   view->Render(scene);
   rmdev->Update();

If you want to render without clearing your target surface, you will need to remove your call to Clear(). If you do this, however, your z-buffer will not get cleared and your objects will not be rendered properly. If you obtain the immediate mode viewport associated with your retained mode viewport, you can clear the z-buffer without clearing the target. Call IDirect3DRMViewport::GetDirect3DViewport() to retrieve the Direct3D immediate mode viewport and then call the immediate mode viewport's Clear() method to clear the z-buffer. You can do this by calling IDirect3DViewport::Clear() with the D3DCLEAR_ZBUFFER flag set.

Sample Code

The following code shows how you can modify your rendering calls to achieve this functionality:

   LPDIRECT3DVIEWPORT d3dview;

   scene->Move(D3DVALUE(1.0));
   view->GetDirect3DViewport(&d3dview);

   int clearflags;
   D3DRECT rc;
   clearflags = D3DCLEAR_ZBUFFER;
   rc.x1 = rc.y1 = 0;
   rc.x2 = 640;
   rc.y2 = 480;
   d3dview->Clear(1, &rc, clearflags);

   view->Render(scene);
   rmdev->Update();


Additional reference words: 4.00
KBCategory: kbrpg kbhowto
KBSubcategory: Direct3D
Keywords : Direct3D kbhowto kbprg
Technology : kbDirectXSDK
Version : 4.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.