private void LoadResources() { m_textBrush = new D2D1.SolidColorBrush(m_D2DContext.d2dContext2, new SharpDX.Color(128, 0, 255)); roundedRecOutColor = new D2D1.SolidColorBrush(m_D2DContext.d2dContext2, new SharpDX.Color(32, 117, 81)); roundedRecInColor = new D2D1.SolidColorBrush(m_D2DContext.d2dContext2, new SharpDX.Color(234, 137, 6)); m_textFormat15 = new TextFormat(m_D2DContext.dw_Factory, "Arial", FontWeight.UltraBold, FontStyle.Normal, fontSize15); m_textFormat10 = new TextFormat(m_D2DContext.dw_Factory, "Arial", FontWeight.Bold, FontStyle.Normal, fontSize10); //m_textFormat10.ParagraphAlignment = ParagraphAlignment.Center; //m_textFormat10.TextAlignment = TextAlignment.Center; m_textFormat10.SetParagraphAlignment(ParagraphAlignment.Center); m_textFormat10.SetTextAlignment(TextAlignment.Center); fontFamily = new System.Drawing.FontFamily("Arial"); m_Bitmap1 = new D2D1.Bitmap1(m_D2DContext.d2dContextCdgText, new Size2(SurfaceW, SurfaceH), BitmapProps1); m_Bitmap1FullScreen = new D2D1.Bitmap1(m_D2DContext.d2dContextCdgText2, new Size2(SurfaceW2, SurfaceH2), BitmapProps1); m_Shadow = new D2D1.Effects.Shadow(m_D2DContext.d2dContextCdgText); m_ShadowFullScreen = new D2D1.Effects.Shadow(m_D2DContext.d2dContextCdgText2); m_affineTransformEffect = new D2D1.Effects.AffineTransform2D(m_D2DContext.d2dContextCdgText2); m_compositeEffect = new D2D1.Effects.Composite(m_D2DContext.d2dContextCdgText2); }
/// <summary> /// Now that we have a CoreWindow object, the DirectX device/context can be created. /// </summary> /// <param name="entryPoint"></param> public void Load(string entryPoint) { // Get the default hardware device and enable debugging. Don't care about the available feature level. // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop. SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport); // Query the default device for the supported device and context interfaces. device = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>(); d3dContext = device.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>(); // Query for the adapter and more advanced DXGI objects. SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface<SharpDX.DXGI.Device2>(); SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter; SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent<SharpDX.DXGI.Factory2>(); // Description for our swap chain settings. SwapChainDescription1 description = new SwapChainDescription1() { // 0 means to use automatic buffer sizing. Width = 0, Height = 0, // 32 bit RGBA color. Format = Format.B8G8R8A8_UNorm, // No stereo (3D) display. Stereo = false, // No multisampling. SampleDescription = new SampleDescription(1, 0), // Use the swap chain as a render target. Usage = Usage.RenderTargetOutput, // Enable double buffering to prevent flickering. BufferCount = 2, // No scaling. Scaling = Scaling.None, // Flip between both buffers. SwapEffect = SwapEffect.FlipSequential, }; // Generate a swap chain for our window based on the specified description. swapChain = new SwapChain1(dxgiFactory2, device, new ComObject(window), ref description); // Get the default Direct2D device and create a context. SharpDX.Direct2D1.Device d2dDevice = new SharpDX.Direct2D1.Device(dxgiDevice2); d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None); // Specify the properties for the bitmap that we will use as the target of our Direct2D operations. // We want a 32-bit BGRA surface with premultiplied alpha. BitmapProperties1 properties = new BitmapProperties1(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), DisplayProperties.LogicalDpi, DisplayProperties.LogicalDpi, BitmapOptions.Target | BitmapOptions.CannotDraw); // Get the default surface as a backbuffer and create the Bitmap1 that will hold the Direct2D drawing target. Surface backBuffer = swapChain.GetBackBuffer<Surface>(0); d2dTarget = new Bitmap1(d2dContext, backBuffer, properties); // Load bitmap images playerBitmap = this.LoadBitmapFromContentFile("/Assets/Bitmaps/player.png"); terrainBitmap = this.LoadBitmapFromContentFile("/Assets/Bitmaps/terrain.png"); // Create hue rotation effect hueRotationEffect = new SharpDX.Direct2D1.Effects.HueRotation(d2dContext); // Create image shadow effect shadowEffect = new SharpDX.Direct2D1.Effects.Shadow(d2dContext); // Create image transform effect affineTransformEffect = new SharpDX.Direct2D1.Effects.AffineTransform2D(d2dContext); affineTransformEffect.SetInputEffect(0, shadowEffect); affineTransformEffect.TransformMatrix = Matrix3x2.Translation(terrainBitmap.PixelSize.Width * 0.25f, terrainBitmap.PixelSize.Height * 0.25f); // Create composite effect compositeEffect = new SharpDX.Direct2D1.Effects.Composite(d2dContext); compositeEffect.InputCount = 2; compositeEffect.SetInputEffect(0, affineTransformEffect); // Create tiling brush for terrain bitmap terrainBrush = new ImageBrush(d2dContext, terrainBitmap, new ImageBrushProperties() { ExtendModeX = ExtendMode.Wrap, ExtendModeY = ExtendMode.Wrap, SourceRectangle = new RectangleF(0, 0, terrainBitmap.Size.Width, terrainBitmap.Size.Height), }); // Create rendertarget for drawing the tiling brush brushTarget = new Bitmap1(d2dContext, new Size2((int)(terrainBitmap.Size.Width * 10), (int)terrainBitmap.Size.Height), new BitmapProperties1() { PixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), BitmapOptions = BitmapOptions.Target }); }