Esempio n. 1
0
        /// <summary>
        /// Called once per frame, the call is the entry point for 3d
        /// rendering. This function sets up render states, clears the
        /// viewport, and renders the scene.
        /// </summary>
        public void Render()
        {
            fpsTimer.StartFrame();
            device.BeginScene();

            // Clear the viewport to black and set the zbuffer to contain 1.0
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
                         System.Drawing.Color.Black, 1.0f, 0);

            // Center view matrix for skybox and disable zbuffer
            // the zbuffer is not needed now because the skybox is a large
            // box that will overwrite all of the window
            Matrix matView, matViewSave;

            matViewSave = device.Transform.View;
            matView     = matViewSave;

            // This translates the camera down 0.3 units to make sure the
            // sky box is under the terrain
            matView.M41                      = 0.0f;
            matView.M42                      = -0.3f;
            matView.M43                      = 0.0f;
            device.Transform.View            = matView;
            device.RenderState.ZBufferEnable = false;
            // Some cards do not disable writing to Z when
            // D3DRS_ZENABLE is FALSE. So do it explicitly
            device.RenderState.ZBufferWriteEnable = false;

            // Render the skybox
            skyBoxMesh.Render();

            // Restore the render states
            device.Transform.View                 = matViewSave;
            device.RenderState.ZBufferEnable      = true;
            device.RenderState.ZBufferWriteEnable = true;

            // Draw the terrain
            terrainMesh.Render();

            // Draw the trees
            DrawTrees();

            // Output statistics
            fpsTimer.Render();

            // End drawing for this scene and flush the frame
            device.EndScene();
            device.Present();

            // stop timing this frame
            fpsTimer.StopFrame();
        }
Esempio n. 2
0
        /// <summary>
        /// Called once per frame, the call is the entry point for 3d
        /// rendering. This function sets up render states, clears the
        /// viewport, and renders the scene.
        /// </summary>
        public void Render()
        {
            fpsTimer.StartFrame();

            device.BeginScene();
            // Clear the viewport
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
                         System.Drawing.Color.Black, 1.0f, 0);

            // Center view matrix for skybox and disable zbuffer
            Matrix matView, matViewSave;

            matViewSave                      = device.Transform.View;
            matView                          = matViewSave;
            matView.M41                      = 0.0f;
            matView.M42                      = -0.3f;
            matView.M43                      = 0.0f;
            device.Transform.View            = matView;
            device.RenderState.ZBufferEnable = false;
            // Some cards do not disable writing to Z when
            // D3DRS_ZENABLE is FALSE. So do it explicitly
            device.RenderState.ZBufferWriteEnable = false;

            // Render the skybox
            skyBoxMesh.Render();

            // Restore the render states
            device.Transform.View                 = matViewSave;
            device.RenderState.ZBufferEnable      = true;
            device.RenderState.ZBufferWriteEnable = true;

            // Draw the terrain
            terrainMesh.Render();

            // Draw the trees
            DrawTrees();

            // Output statistics
            fpsTimer.Render();

            device.EndScene();
            device.Present();

            fpsTimer.StopFrame();
        }
Esempio n. 3
0
        /// <summary>
        /// Called once per frame, the call is the entry point for 3d
        /// rendering. This function sets up render states, clears the
        /// viewport, and renders the scene.
        /// </summary>
        public void Render()
        {
            // Clear the viewport
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer |
                         ClearFlags.Stencil, fogColor, 1.0f, 0);

            device.BeginScene();

            device.Transform.World = terrainMatrix;
            terrainObject.Render();

            device.Transform.World = objectMatrix;
            airplane.Render(true, false);

            // Render the shadow volume into the stenicl buffer, then add
            // it into the scene
            RenderShadow();
            DrawShadow();

            device.EndScene();
            device.Present();
        }