Microsoft DirectX 8.1 (Visual Basic) |
The CreateDevice sample project uses a timer to render the screen at a given interval. The sample sets the timer's Interval property to 40. This means that every forty milliseconds the function Timer1_Timer will fire. When the timer fires, it calls the application-defined function Render, which renders and displays the scene. The CreateDevice sample project clears the back buffer to a blue color, transfers the contents of the back buffer to the front buffer, and presents the front buffer to the screen.
To render a scene, start by calling the Direct3DDevice8.Clear method.
g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, &HFF&, 1#, 0
The first two parameters accepted by Clear inform Microsoft® Direct3D® of the size and address of the array of rectangles to be cleared The array of rectangles describes the areas on the render target surface to be cleared.
In most cases, you will use a single rectangle that covers the entire rendering target. This is done by setting the first parameter to 0 and the second parameter to ByVal 0. The third parameter determines the method's behavior. You can specify a flag to clear a render-target surface, an associated depth buffer, the stencil buffer, or any combination of the three. This tutorial does not use a depth buffer, so 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. The CreateDevice sample project sets the clear color for the render target surface to blue (&HFF&). The final two parameters are ignored by the Clear method because the corresponding flags are not present.
After clearing the viewport, the CreateDevice sample project informs Direct3D that rendering will begin, then signals that rendering is complete, as shown in the following code fragment.
' Begin the scene. g_D3DDevice.BeginScene ' Rendering of scene objects occur here. ' End the scene. g_D3DDevice.EndScene
The Direct3DDevice8.BeginScene and Direct3DDevice8.EndScene methods signal to the system when rendering is beginning or is complete. You can call rendering methods only between calls to these methods. Even if rendering methods fail, you should call EndScene before calling BeginScene again.
After rendering the scene, you display it by using the Direct3DDevice8.Present method.
g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
The first two parameters accepted by Present are a source rectangle and a destination rectangle. This sample presents the entire back buffer to the front buffer by setting these two parameters to ByVal 0. The third parameter sets the destination window for this presentation. Because this parameter is set to 0, the hWndDeviceWindow member of D3DPRESENT_PARAMETERS is used. The fourth parameter is the DirtyRegion parameter and in most cases should be set to ByVal 0.
The final step for this tutorial, shutting down the application, is described in Step 4: Shutting Down.