public override void Draw(GameTime gameTime, Frame frame) { var ir = new ImperativeRenderer(frame, Materials); ir.AutoIncrementLayer = true; ir.Clear(color: ClearColor); var rect1 = new Rectangle(0, 0, 32, 32); var rect2 = new Rectangle(1, 1, 30, 30); var drawSet = (Action <Rectangle, float>)((r, y) => { DrawRow(ref ir, 0f, y + 0f, SamplerState.PointClamp, r); DrawRow(ref ir, 0.5f, y + 1 + 64f, SamplerState.PointClamp, r); DrawRow(ref ir, 0f, (y + 3 + 128) + 0.5f, SamplerState.PointClamp, r); DrawRow(ref ir, 0f, y + 5 + 192f, SamplerState.LinearClamp, r); DrawRow(ref ir, 0.5f, y + 7 + 256f, SamplerState.LinearClamp, r); DrawRow(ref ir, 0f, (y + 9 + 320) + 0.5f, SamplerState.LinearClamp, r); }); drawSet(rect1, 0f); drawSet(rect2, (70f * 6)); var cornerSamplers = SamplerState.LinearClamp; ir.Draw(TestTexture, new Vector2(Graphics.PreferredBackBufferWidth - 1, Graphics.PreferredBackBufferHeight - 1), origin: new Vector2(1, 1), samplerState: cornerSamplers); ir.Draw(TestTexture, new Vector2(0, Graphics.PreferredBackBufferHeight - 1), origin: new Vector2(0, 1), samplerState: cornerSamplers); ir.Draw(TestTexture, new Vector2(Graphics.PreferredBackBufferWidth - 1, 0), origin: new Vector2(1, 0), samplerState: cornerSamplers); }
private void DrawRow(ref ImperativeRenderer ir, float x, float y, SamplerState samplerState) { var sourceRect = new Rectangle(1, 1, 30, 30); ir.Draw(TestTexture, x, y, sourceRect, samplerState: samplerState); x += 64f; ir.Draw(TestTexture, x, y, sourceRect, scaleX: 2f, scaleY: 2f, samplerState: samplerState); x += 96f; for (float r = 0.1f; r < Math.PI / 2f; r += 0.2f) { ir.Draw(TestTexture, x, y, sourceRect, rotation: r, samplerState: samplerState); x += 64f; } }
public override void Draw(GameTime gameTime, Frame frame) { using (var rtb = BatchGroup.ForRenderTarget(frame, -1, Rt)) { var ir = new ImperativeRenderer(rtb, Materials); ir.Clear(color: Color.Transparent); ir.SetViewport(new Rectangle(128, 128, 256, 256), true); ir.FillRectangle(new Rectangle(0, 0, 512, 512), Color.Black, customMaterial: Vpos); } { var ir = new ImperativeRenderer(frame, Materials) { AutoIncrementLayer = true }; ir.SetViewport(null, true); ir.Clear(color: Color.SteelBlue); const float scale = 0.65f; var pos = new Vector2(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight) / 2f; ir.Draw( Texture, pos, origin: Vector2.One * 0.5f, scale: Vector2.One * scale, blendState: BlendState.Opaque, samplerState: SamplerState.LinearClamp ); ir.DrawString( Font, "Hello, World!", Vector2.Zero, blendState: BlendState.AlphaBlend, material: Materials.ScreenSpaceShadowedBitmap ); var sg = ir.MakeSubgroup(); sg.AutoIncrementLayer = true; sg.SetViewport(new Rectangle(128, 128, 512, 512), true); sg.FillRectangle(new Rectangle(0, 0, 1024, 1024), Color.Black, customMaterial: Vpos); sg.SetViewport(null, true); ir.Draw( Rt, new Vector2(1920 - 512, 0) ); } }
private void DrawRow(ref ImperativeRenderer ir, float x, float y, SamplerState samplerState, Rectangle sourceRect, bool mirror) { var tlState = samplerState; if ((x == 0) && (y == 0)) { tlState = SamplerState.LinearClamp; } ir.Draw(TestTexture, x, y, sourceRect, samplerState: tlState, mirrorX: mirror); x += 64f; ir.Draw(TestTexture, x, y, sourceRect, scaleX: 2f, scaleY: 2f, samplerState: samplerState, mirrorX: mirror); x += 96f; for (float r = 0.1f; r < Math.PI / 2f; r += 0.2f) { ir.Draw(TestTexture, x, y, sourceRect, rotation: r, samplerState: samplerState, mirrorX: mirror); x += 64f; } }
private void DrawHud(Frame frame) { Rectangle titleSafeArea = GraphicsDevice.Viewport.TitleSafeArea; Vector2 hudLocation = new Vector2(titleSafeArea.X, titleSafeArea.Y); Vector2 center = new Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f, titleSafeArea.Y + titleSafeArea.Height / 2.0f); // Draw time remaining. Uses modulo division to cause blinking when the // player is running out of time. string timeString = "TIME: " + level.TimeRemaining.Minutes.ToString("00") + ":" + level.TimeRemaining.Seconds.ToString("00"); Color timeColor; if (level.TimeRemaining > WarningTime || level.ReachedExit || (int)level.TimeRemaining.TotalSeconds % 2 == 0) { timeColor = Color.Yellow; } else { timeColor = Color.Red; } var renderer = new ImperativeRenderer(frame, materials, 100, blendState: BlendState.AlphaBlend); renderer.DrawString(hudFont, timeString, hudLocation, timeColor, sortKey: 1); renderer.DrawString(hudFont, timeString, hudLocation + Vector2.One, Color.Black, sortKey: 0); var timeHeight = hudFont.MeasureString(timeString).Y; hudLocation.Y = (float)Math.Floor(hudLocation.Y + (timeHeight * 1.2f)); var scoreText = "SCORE: " + level.Score; renderer.DrawString(hudFont, scoreText, hudLocation, Color.Yellow, sortKey: 1); renderer.DrawString(hudFont, scoreText, hudLocation + Vector2.One, Color.Black, sortKey: 0); // Determine the status overlay message to show. Texture2D status = null; if (level.TimeRemaining == TimeSpan.Zero) { if (level.ReachedExit) { status = winOverlay; } else { status = loseOverlay; } } else if (!level.Player.IsAlive) { status = diedOverlay; } if (status != null) { // Draw status message. Vector2 statusSize = new Vector2(status.Width, status.Height); renderer.Draw(status, center - statusSize / 2); } }