private void InitD3D() { _dxDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0); EnsureOutputBuffers(); FontDescription fontDesc = new FontDescription { Height = 24, Width = 0, Weight = 0, MipLevels = 1, IsItalic = false, CharacterSet = FontCharacterSet.Default, Precision = FontPrecision.Default, Quality = FontQuality.Default, PitchAndFamily = FontPitchAndFamily.Default | FontPitchAndFamily.DontCare, FaceName = "Times New Roman" }; _dxFont = new Font(_dxDevice, fontDesc); _textureManager = new DxTextureManager(_dxDevice); // _dxEffect = new DxEffect(_dxDevice); _dxCube = new DxCube(_dxDevice); CrateKinectPointsRenderer(KinectPointsRendererType.Billboard); ShaderResourceView texArray = _textureManager.CreateTexArray("flares", @"Assets\flare0.dds"); _fire = new DxParticleSystemRenderer(_dxDevice, texArray, 500); _dxDevice.Flush(); }
/// <summary> /// Initializes a new instance of the <see cref="UserInterfaceRenderer10"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="width">The width of the renderable area.</param> /// <param name="height">The height of the renderable area.</param> public UserInterfaceRenderer10(D3D.Device device, int width, int height) { if (device == null) throw new ArgumentNullException("device"); if (width < 0) throw new ArgumentException("Value must be positive.", "width"); if (height < 0) throw new ArgumentException("Value must be positive.", "height"); this.device = device; halfWidth = width / 2; halfHeight = height / 2; font = new D3D.Font(device, 18, 0, D3D.FontWeight.Bold, 0, false, D3D.FontCharacterSet.Default, D3D.FontPrecision.Default, D3D.FontQuality.Antialiased, D3D.FontPitchAndFamily.Default, "Arial"); sprite = new SlimDX.Direct3D10.Sprite(device, 0); lineBuffer = new DynamicPrimitiveBuffer10<ColoredVertex>(device); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream("SampleFramework.Resources.UserInterface10.fx")) using (StreamReader reader = new StreamReader(stream)) { effect = D3D.Effect.FromString(device, reader.ReadToEnd(), "fx_4_0"); } technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); ShaderSignature signature = pass.Description.Signature; inputLayout = new D3D.InputLayout(device, signature, new[] { new D3D.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0), new D3D.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, D3D.InputElement.AppendAligned, 0 ) }); }
public void Run() { Device device; SwapChain swapChain; RenderTargetView renderTarget; EmptyWindow.CreateDeviceSwapChainAndRenderTarget(mForm, out device, out swapChain, out renderTarget); // buffer size 1 .. 4096 (0 defaults to 4096) var sprite = new Sprite(device, 10); var font = new Font(device, 20, "ARIAL"); Application.Idle += delegate { device.ClearRenderTargetView(renderTarget, new Color4(1, 0, 0)); var rectangle = new Rectangle(10, 10, 400, 300); sprite.Begin(SpriteFlags.None); font.Draw(sprite, "Hello from SlimDX", rectangle, FontDrawFlags.Left, (uint)Color.Yellow.ToArgb()); sprite.End(); swapChain.Present(0, PresentFlags.None); Application.DoEvents(); }; Application.Run(mForm); }
protected override void DrawText(Object dev, String text, String text2 = null, int alpha = 0) { Texture2D texture = (Texture2D)dev; SlimDX.Direct3D10.Device device = texture.Device; #region Save BlendState. Maybe can be done with less code? BlendState bs = device.OutputMerger.BlendState; Color4 bf = device.OutputMerger.BlendFactor; int bsm = device.OutputMerger.BlendSampleMask; int dsr = device.OutputMerger.DepthStencilReference; DepthStencilState dss = device.OutputMerger.DepthStencilState; #endregion if (_font == null) { _sprite = new Sprite(device, 256); _font = new SlimDX.Direct3D10.Font(device, _fd); } _sprite.Begin(SpriteFlags.None); _font.Draw(_sprite, text, new System.Drawing.Rectangle(0, 0, texture.Description.Width, texture.Description.Height), FontDrawFlags.Top | FontDrawFlags.Right | FontDrawFlags.NoClip, System.Drawing.Color.Red); if (alpha > 0) { Color c = Color.FromArgb(alpha, System.Drawing.Color.Red); _font.Draw(_sprite, text2, new System.Drawing.Rectangle(0, 15, texture.Description.Width, texture.Description.Height - 15), FontDrawFlags.Top | FontDrawFlags.Right | FontDrawFlags.NoClip, c); } _sprite.End(); #region Restore Blend State device.OutputMerger.BlendState = bs; device.OutputMerger.DepthStencilState = dss; device.OutputMerger.BlendSampleMask = bsm; device.OutputMerger.BlendFactor = bf; device.OutputMerger.DepthStencilReference = dsr; #endregion }
private void InitDebugFont() { FontDescription fontDesc = new FontDescription() { Height = 16, Width = 0, Weight = FontWeight.Bold, MipLevels = 1, IsItalic = false, PitchAndFamily = FontPitchAndFamily.Default | FontPitchAndFamily.DontCare, FaceName = "Arial" }; debugFont = new SlimDX.Direct3D10.Font(device, fontDesc); }
private void DestroyD3D() { _textureManager.Dispose(); _dxCube.Dispose(); //_dxEffect.Dispose(); _kinectPoints.Dispose(); if (_dxFont != null) { _dxFont.Dispose(); _dxFont = null; } if (DepthTexture != null) { DepthTexture.Dispose(); DepthTexture = null; } if (SharedTexture != null) { SharedTexture.Dispose(); SharedTexture = null; } if (_dxRenderView != null) { _dxRenderView.Dispose(); _dxRenderView = null; } if (_dxDepthStencilView != null) { _dxDepthStencilView.Dispose(); _dxDepthStencilView = null; } if (_dxDevice != null) { _dxDevice.Dispose(); _dxDevice = null; } }
/// <summary> /// Initializes a new instance of the <see cref="UserInterfaceRenderer10"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="width">The width of the renderable area.</param> /// <param name="height">The height of the renderable area.</param> public UserInterfaceRenderer10(D3D.Device device, int width, int height) { if (device == null) { throw new ArgumentNullException("device"); } if (width < 0) { throw new ArgumentException("Value must be positive.", "width"); } if (height < 0) { throw new ArgumentException("Value must be positive.", "height"); } this.device = device; halfWidth = width / 2; halfHeight = height / 2; font = new D3D.Font(device, 18, 0, D3D.FontWeight.Bold, 0, false, D3D.FontCharacterSet.Default, D3D.FontPrecision.Default, D3D.FontQuality.Antialiased, D3D.FontPitchAndFamily.Default, "Arial"); sprite = new SlimDX.Direct3D10.Sprite(device, 0); lineBuffer = new DynamicPrimitiveBuffer10 <ColoredVertex>(device); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream("SampleFramework.Resources.UserInterface10.fx")) using (StreamReader reader = new StreamReader(stream)) { effect = D3D.Effect.FromString(device, reader.ReadToEnd(), "fx_4_0"); } technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); ShaderSignature signature = pass.Description.Signature; inputLayout = new D3D.InputLayout(device, signature, new[] { new D3D.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0), new D3D.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, D3D.InputElement.AppendAligned, 0) }); }
public D3D10.Font LoadFont(String name, D3D10.FontDescription desc) { if (fonts.ContainsKey(name)) return fonts[name]; D3D10.Font temp = new SlimDX.Direct3D10.Font(Game.gameClass.GetDevice(), desc); fonts.Add(name,temp); return temp; }
private void DrawText(SlimDX.Direct3D10.Font font, Vector2 pos, string text, Color4 color) { font.Draw(null, text, new System.Drawing.Rectangle((int)pos.X, (int)pos.Y, 0, 0), SlimDX.Direct3D10.FontDrawFlags.NoClip, color); }
protected override void DrawText(Object dev, String text, String text2 = null, int alpha = 0) { Texture2D texture = (Texture2D)dev; SlimDX.Direct3D10.Device device = texture.Device; #region Save BlendState. Maybe can be done with less code? BlendState bs = device.OutputMerger.BlendState; Color4 bf = device.OutputMerger.BlendFactor; int bsm=device.OutputMerger.BlendSampleMask; int dsr = device.OutputMerger.DepthStencilReference; DepthStencilState dss = device.OutputMerger.DepthStencilState; #endregion if (_font == null) { _sprite = new Sprite(device, 256); _font = new SlimDX.Direct3D10.Font(device, _fd); } _sprite.Begin(SpriteFlags.None); _font.Draw(_sprite, text, new System.Drawing.Rectangle(0, 0, texture.Description.Width, texture.Description.Height), FontDrawFlags.Top | FontDrawFlags.Right | FontDrawFlags.NoClip, System.Drawing.Color.Red); if (alpha > 0) { Color c = Color.FromArgb(alpha, System.Drawing.Color.Red); _font.Draw(_sprite, text2, new System.Drawing.Rectangle(0, 15, texture.Description.Width, texture.Description.Height-15), FontDrawFlags.Top | FontDrawFlags.Right | FontDrawFlags.NoClip, c); } _sprite.End(); #region Restore Blend State device.OutputMerger.BlendState = bs; device.OutputMerger.DepthStencilState = dss; device.OutputMerger.BlendSampleMask = bsm; device.OutputMerger.BlendFactor = bf; device.OutputMerger.DepthStencilReference = dsr; #endregion }