/// <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(); // 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(); } }