private void _drawDesktopOutline(SharpDX.Direct2D1.DeviceContext d2dContext) { //BORDER d2dContext.Transform = Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale); d2dContext.DrawRectangle( _layoutDeviceScreenSize, _generalLightGrayColor, 3 ); //WIDTH d2dContext.Transform = Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale); d2dContext.FillRectangle( new RectangleF(0, -30, 100, 30), _generalLightGrayColor ); d2dContext.Transform = Matrix.Translation(10, 0, 0) * Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale); d2dContext.DrawText(_layoutDetail.Width.ToString(), _generalTextFormat, new RectangleF(0, -30, 100, 30), _generalLightWhiteColor); ////HEIGHT double angleRadians = 90 * Math.PI / 180; //90 degrees d2dContext.Transform = Matrix.RotationZ((float)angleRadians) * Matrix.Identity * Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale); d2dContext.FillRectangle( new RectangleF(0, 0, 100, 30), _generalLightGrayColor ); d2dContext.Transform = Matrix.RotationZ((float)angleRadians) * Matrix.Translation(0, 10, 0) * Matrix.Translation(_globalTranslation) * Matrix.Scaling(_globalScale); d2dContext.DrawText(_layoutDetail.Height.ToString(), _generalTextFormat, new RectangleF(0, 0, 100, 30), _generalLightWhiteColor); }
private void _drawDebuggingInfo(SharpDX.Direct2D1.DeviceContext d2dContext) { if (_gt != null) { d2dContext.Transform = Matrix.Identity; d2dContext.DrawText("TotalGameTime (s) : " + _gt.TotalGameTime.TotalSeconds.ToString(), _debugTextFormat, _debugLine1, _generalRedColor); d2dContext.DrawText("FrameCount : " + _gt.FrameCount.ToString(), _debugTextFormat, _debugLine2, _generalRedColor); d2dContext.DrawText("ElapsedGameTime (s) : " + _gt.ElapsedGameTime.TotalSeconds.ToString(), _debugTextFormat, _debugLine3, _generalRedColor); d2dContext.DrawText("IsRunningSlowly : " + _gt.IsRunningSlowly.ToString(), _debugTextFormat, _debugLine4, _generalRedColor); d2dContext.DrawText("FPS : " + (_gt.FrameCount / _gt.TotalGameTime.TotalSeconds).ToString(), _debugTextFormat, _debugLine5, _generalRedColor); } }
void DrawText(SharpDX.Direct2D1.DeviceContext context, RectangleF rect, string text, string font, int size, TextAlignment alignment, ParagraphAlignment pAlignment) { if (_format == null) { using (var factory = new Factory()) { _format = new TextFormat(factory, font, size); _format.TextAlignment = alignment; _format.ParagraphAlignment = pAlignment; } } context.DrawText(text, _format, rect, _brush); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RenderForm form = new RenderForm("Kinect simple pilot sample"); RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport); RenderContext context = new RenderContext(device); DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle); //Allow to draw using direct2d on top of swapchain var context2d = new SharpDX.Direct2D1.DeviceContext(swapChain.Texture.QueryInterface<SharpDX.DXGI.Surface>()); //Call release on texture since queryinterface does an addref Marshal.Release(swapChain.Texture.NativePointer); var textFormat = new SharpDX.DirectWrite.TextFormat(device.DWriteFactory, "Arial", 16.0f); var blackBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.Black); var whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.White); KinectSensor sensor = KinectSensor.GetDefault(); sensor.Open(); bool doQuit = false; KinectSensorColorRGBAFrameProvider provider = new KinectSensorColorRGBAFrameProvider(sensor); DynamicColorRGBATextureProcessor colorProcessor = new DynamicColorRGBATextureProcessor(provider, device); KinectPilotProcessor pilot = KinectPilotProcessor.Default; KinectSensorBodyFrameProvider bodyFrameProvider = new KinectSensorBodyFrameProvider(sensor); bodyFrameProvider.FrameReceived += (sender, args) => { var body = args.FrameData.TrackedOnly().ClosestBodies().FirstOrDefault(); if (body != null) { pilot.Process(body.GetJointTable()); } }; form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } }; RenderLoop.Run(form, () => { if (doQuit) { form.Dispose(); return; } colorProcessor.Update(context); context.RenderTargetStack.Push(swapChain); device.Primitives.ApplyFullTri(context, colorProcessor.Texture.ShaderView); device.Primitives.FullScreenTriangle.Draw(context); context.RenderTargetStack.Pop(); context2d.BeginDraw(); var rect = new SharpDX.RectangleF(0, 0, 200, 130); context2d.FillRectangle(rect, blackBrush); context2d.DrawText("Elevation: " + pilot.Elevation, textFormat, rect, whiteBrush); rect.Top += 30; context2d.DrawText("Steering Y: " + pilot.SteeringY, textFormat, rect, whiteBrush); rect.Top += 30; context2d.DrawText("Steering Z: " + pilot.SterringZ, textFormat, rect, whiteBrush); rect.Top += 30; context2d.DrawText("Push: " + pilot.Push, textFormat, rect, whiteBrush); context2d.EndDraw(); swapChain.Present(0, SharpDX.DXGI.PresentFlags.None); }); swapChain.Dispose(); context.Dispose(); device.Dispose(); colorProcessor.Dispose(); provider.Dispose(); sensor.Close(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RenderForm form = new RenderForm("Kinect simple pilot sample"); RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport); RenderContext context = new RenderContext(device); DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle); //Allow to draw using direct2d on top of swapchain var context2d = new SharpDX.Direct2D1.DeviceContext(swapChain.Texture.QueryInterface <SharpDX.DXGI.Surface>()); //Call release on texture since queryinterface does an addref Marshal.Release(swapChain.Texture.NativePointer); var textFormat = new SharpDX.DirectWrite.TextFormat(device.DWriteFactory, "Arial", 16.0f); var blackBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.Black); var whiteBrush = new SharpDX.Direct2D1.SolidColorBrush(context2d, SharpDX.Color.White); KinectSensor sensor = KinectSensor.GetDefault(); sensor.Open(); bool doQuit = false; KinectSensorColorRGBAFrameProvider provider = new KinectSensorColorRGBAFrameProvider(sensor); DynamicColorRGBATextureProcessor colorProcessor = new DynamicColorRGBATextureProcessor(provider, device); KinectPilotProcessor pilot = KinectPilotProcessor.Default; KinectSensorBodyFrameProvider bodyFrameProvider = new KinectSensorBodyFrameProvider(sensor); bodyFrameProvider.FrameReceived += (sender, args) => { var body = args.FrameData.TrackedOnly().ClosestBodies().FirstOrDefault(); if (body != null) { pilot.Process(body.GetJointTable()); } }; form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } }; RenderLoop.Run(form, () => { if (doQuit) { form.Dispose(); return; } colorProcessor.Update(context); context.RenderTargetStack.Push(swapChain); device.Primitives.ApplyFullTri(context, colorProcessor.Texture.ShaderView); device.Primitives.FullScreenTriangle.Draw(context); context.RenderTargetStack.Pop(); context2d.BeginDraw(); var rect = new SharpDX.RectangleF(0, 0, 200, 130); context2d.FillRectangle(rect, blackBrush); context2d.DrawText("Elevation: " + pilot.Elevation, textFormat, rect, whiteBrush); rect.Top += 30; context2d.DrawText("Steering Y: " + pilot.SteeringY, textFormat, rect, whiteBrush); rect.Top += 30; context2d.DrawText("Steering Z: " + pilot.SterringZ, textFormat, rect, whiteBrush); rect.Top += 30; context2d.DrawText("Push: " + pilot.Push, textFormat, rect, whiteBrush); context2d.EndDraw(); swapChain.Present(0, SharpDX.DXGI.PresentFlags.None); }); swapChain.Dispose(); context.Dispose(); device.Dispose(); colorProcessor.Dispose(); provider.Dispose(); sensor.Close(); }