Platform SDK: DirectX |
This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.
Once the model's geometry has been updated to reflect the desired animation, you can render the scene. The Triangle tutorial code takes a typical approach: the RenderScene application-defined subroutine starts by clearing the viewport:
Private Sub RenderScene() ' Clear the viewport to a blue color. g_d3dDevice.Clear 1, g_d3drcViewport(), D3DCLEAR_TARGET, &HFF, 0, 0
The preceding code calls the Direct3DDevice7.Clear method to clear the viewport. The first two arguments accepted by the Clear method are the array of rectangles describing the area or areas on the render target to be cleared and the value that informs the method how many rectangles from the array should be cleared. In most cases, as in the Triangle tutorial application, you will use a single rectangle that covers the entire render target. The third argument determines the method's behavior. Clear can clear the render-target surface, the associated depth buffer, the stencil buffer, or any combination of the three. Because this tutorial does not use a depth buffer, D3DCLEAR_TARGET is the only flag used. The last three parameters are set to reflect clearing values for the render target, depth buffer, and stencil buffer, respectively. The Triangle tutorial set the clear color for the render target surface to blue. Since the remaining parameters are not used in this tutorial, the code sets them to zero. The Clear method will ignore arguments when the corresponding flag is not specified.
After clearing the viewport, the tutorial code informs Direct3D that rendering will begin, renders the scene, then signals that rendering is complete, as shown here:
' Begin the scene, render the triangle, then complete the scene g_d3dDevice.BeginScene Call g_d3dDevice.DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_VERTEX, _ g_TriangleVert(0), 6, D3DDP_DEFAULT) g_d3dDevice.EndScene
The Direct3DDevice7.BeginScene and Direct3DDevice7.EndScene methods notify the system when rendering is beginning or is complete. You can only call rendering methods between calls to these methods. Even if rendering methods fail, you should call EndScene before calling BeginScene again.
After rendering the scene to the off-screen render target, you can update the user's display. The Triangle tutorial application demonstrates this in Step 4.3: Update the Display.