/// <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(); //Clear the backbuffer to a black color device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); //Begin the scene device.BeginScene(); // set the vertexbuffer stream source device.SetStreamSource(0, vertexBuffer, 0); // set fill mode device.RenderState.FillMode = FillMode.Solid; // set the indices device.Indices = indexBuffer; //use the indices buffer device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, bufferSize * bufferSize, 0, vert_size / 3); // Write instructions on the screen drawingFont.DrawText(null, "Tap screen to generate\n new fractal.", new Point(2, 40), System.Drawing.Color.White); // output statistics fpsTimer.Render(); device.EndScene(); device.Present(); fpsTimer.StopFrame(); }
/// <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(); }
/// <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(); }
/// <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() { MatrixFixed matWorld; MatrixFixed matTrans; MatrixFixed matRotate; fpsTimer.StartFrame(); // Clear the viewport to a blue color (0x000000ff = blue) device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x000000ff, 1.0f, 0); device.BeginScene(); // Turn on light #0 and #2, and turn off light #1 device.LightsFixed[0].Enabled = true; device.LightsFixed[1].Enabled = false; device.LightsFixed[2].Enabled = true; // Draw the floor matTrans = new MatrixFixed(Matrix.Translation(-5.0f, -5.0f, -5.0f)); matRotate = new MatrixFixed(Matrix.RotationZ(0.0f)); matWorld = MatrixFixed.Multiply(matRotate, matTrans); device.Transform.WorldFixed = matWorld; wallMesh.DrawSubset(0); // Draw the back wall matTrans = new MatrixFixed(Matrix.Translation(5.0f, -5.0f, -5.0f)); matRotate = new MatrixFixed(Matrix.RotationZ((float)Math.PI / 2)); matWorld = MatrixFixed.Multiply(matRotate, matTrans); device.Transform.WorldFixed = matWorld; wallMesh.DrawSubset(0); // Draw the side wall matTrans = new MatrixFixed(Matrix.Translation(-5.0f, -5.0f, 5.0f)); matRotate = new MatrixFixed(Matrix.RotationX((float)-Math.PI / 2)); matWorld = MatrixFixed.Multiply(matRotate, matTrans); device.Transform.WorldFixed = matWorld; wallMesh.DrawSubset(0); // Turn on light #1, and turn off light #0 and #2 device.LightsFixed[0].Enabled = false; device.LightsFixed[1].Enabled = true; device.LightsFixed[2].Enabled = false; // Draw the mesh representing the light if (lightData.Type == LightType.Point) { // Just position the point light -- no need to orient it matWorld = new MatrixFixed(Matrix.Translation(lightData.Position.X, lightData.Position.Y, lightData.Position.Z)); device.Transform.WorldFixed = matWorld; sphereMesh.DrawSubset(0); } else { // Position the light and point it in the light's direction Vector3 vecFrom = new Vector3(lightData.Position.X, lightData.Position.Y, lightData.Position.Z); Vector3 vecAt = new Vector3( lightData.Position.X + lightData.Direction.X, lightData.Position.Y + lightData.Direction.Y, lightData.Position.Z + lightData.Direction.Z); Vector3 vecUp = new Vector3(0, 1, 0); Matrix matWorldInv; matWorldInv = Matrix.LookAtLH(vecFrom, vecAt, vecUp); matWorld = new MatrixFixed(Matrix.Invert(matWorldInv)); device.Transform.WorldFixed = matWorld; coneMesh.DrawSubset(0); } // Output statistics fpsTimer.Render(); device.EndScene(); device.Present(); fpsTimer.StopFrame(); }
/// <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(); // clears the frame device.Clear(ClearFlags.Target, 0, 1.0f, 0); try { // start drawing commands device.BeginScene(); int height = ClientRectangle.Height; int width = ClientRectangle.Width; System.Drawing.Rectangle rect; // Demonstration 1 // Draw a simple line using DrawText // Pass in DrawTextFormat.NoClip so we don't have to calc // the bottom/right of the rect font1.DrawText(null, "This is a trivial call to Font.DrawText", new System.Drawing.Rectangle(5, 150, 0, 0), DrawTextFormat.NoClip, System.Drawing.Color.Red); // Demonstration 2 // Allow multiple draw calls to sort by texture changes // by Sprite When drawing 2D text use flags: // SpriteFlags.AlphaBlend | SpriteFlags.SortTexture. textDrawerSprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortTexture); rect = new System.Drawing.Rectangle(5, height - 15 * 6, 0, 0); font2.DrawText(textDrawerSprite, "These are multiple calls to Font.DrawText()", rect, DrawTextFormat.NoClip, Color.White); rect = new System.Drawing.Rectangle(5, height - 15 * 5, 0, 0); font2.DrawText(textDrawerSprite, "using the same Sprite. The font now caches", rect, DrawTextFormat.NoClip, Color.White); rect = new System.Drawing.Rectangle(5, height - 15 * 4, 0, 0); font2.DrawText(textDrawerSprite, "letters on one or more textures. In order", rect, DrawTextFormat.NoClip, Color.White); rect = new System.Drawing.Rectangle(5, height - 15 * 3, 0, 0); font2.DrawText(textDrawerSprite, "to sort by texturestate changes on multiple", rect, DrawTextFormat.NoClip, Color.White); rect = new System.Drawing.Rectangle(5, height - 15 * 2, 0, 0); font2.DrawText(textDrawerSprite, "calls to DrawText() pass a Sprite and use flags", rect, DrawTextFormat.NoClip, Color.White); rect = new System.Drawing.Rectangle(5, height - 15 * 1, 0, 0); font2.DrawText(textDrawerSprite, "SpriteFlags.AlphaBlend | SpriteFlags.SortTexture", rect, DrawTextFormat.NoClip, Color.White); textDrawerSprite.End(); // Demonstration 3: // Word wrapping and unicode text. // Note that not all fonts support dynamic font linking. System.Drawing.Rectangle rc = new System.Drawing.Rectangle(10, 35, width - 30, height - 10); font2.DrawText(null, bigText, rc, DrawTextFormat.Left | DrawTextFormat.WordBreak | DrawTextFormat.ExpandTabs, System.Drawing.Color.CornflowerBlue); // write the fps fpsTimer.Render(); } finally { // end the drawing commands and copy to screen device.EndScene(); device.Present(); fpsTimer.StopFrame(); } }