public void CreateWindowSizeDependentResources() { var context = this.deviceResources.D2DRenderTarget; var dwriteFactory = this.deviceResources.DWriteFactory; string text = "Hello, World!"; byte[] bitmapBytes = File.ReadAllBytes(@"texturedata.bin"); this.bitmap = context.CreateBitmap(new D2D1SizeU(256, 256), bitmapBytes, 256 * 4, new D2D1BitmapProperties(new D2D1PixelFormat(DxgiFormat.R8G8B8A8UNorm, D2D1AlphaMode.Premultiplied), 96.0f, 96.0f)); this.bitmapBrush = context.CreateBitmapBrush(this.bitmap, new D2D1BitmapBrushProperties(D2D1ExtendMode.Wrap, D2D1ExtendMode.Wrap, D2D1BitmapInterpolationMode.Linear)); this.textBrush = context.CreateSolidColorBrush(new D2D1ColorF(D2D1KnownColor.Red)); this.textLayout = dwriteFactory.CreateTextLayout( text, this.textFormat, this.deviceResources.ConvertPixelsToDipsX(this.deviceResources.BackBufferWidth), this.deviceResources.ConvertPixelsToDipsY(this.deviceResources.BackBufferHeight)); this.textLayout.SetFontSize(140.0f, new DWriteTextRange(0, (uint)text.Length)); using (var typography = dwriteFactory.CreateTypography()) { typography.AddFontFeature(new DWriteFontFeature(DWriteFontFeatureTag.StylisticSet7, 1)); this.textLayout.SetTypography(typography, new DWriteTextRange(0, 13)); } }
public void Update(StepTimer timer) { if (!this.IsEnabled) { return; } if (timer == null) { throw new ArgumentNullException("timer"); } var time = timer.TotalTime; uint fps = timer.FramesPerSecond; text.Clear(); if (this.ShowPerformanceTime) { text.Append("E:"); text.Append(this.performanceTime.EventTime); text.Append(", U:"); text.Append(this.performanceTime.UpdateTime); text.Append(", R:"); text.Append(this.performanceTime.RenderTime); text.Append(", P:"); text.Append(this.performanceTime.PresentTime); text.Append("\n"); } if (this.ShowTime) { text.Append(time); text.Append("\n"); } if (fps > 0) { text.Append(fps); } else { text.Append("-"); } text.Append(" FPS"); DWriteUtils.DisposeAndNull(ref this.textLayout); this.textLayout = this.deviceResources.DWriteFactory.CreateTextLayout(text.ToString(), this.textFormat, 600, 400); this.isInitialized = true; }