Example #1
0
        /// <summary>
        /// Creates a ShaderResourceView from a bitmap in a Stream.
        /// </summary>
        /// <param name="device">The Direct3D device that will own the ShaderResourceView</param>
        /// <param name="stream">Any Windows Imaging Component decodable image</param>
        /// <returns>A ShaderResourceView object with the loaded texture.</returns>
        public static ShaderResourceView LoadTexture(D3DDevice device, Stream stream)
        {
            ImagingFactory factory = ImagingFactory.Create();

            BitmapDecoder bitmapDecoder =
                factory.CreateDecoderFromStream(
                    stream,
                    DecodeMetadataCacheOption.OnDemand);

            return(LoadFromDecoder(device, factory, bitmapDecoder));
        }
Example #2
0
        /// <summary>
        /// Creates a ShaderResourceView from a bitmap in a file.
        /// </summary>
        /// <param name="device">The Direct3D device that will own the ShaderResourceView</param>
        /// <param name="filePath">Any Windows Imaging Component decodable image</param>
        /// <returns>A ShaderResourceView object with the loaded texture.</returns>
        public static ShaderResourceView LoadTexture(D3DDevice device, String filePath)
        {
            ImagingFactory factory = ImagingFactory.Create();

            BitmapDecoder bitmapDecoder =
                factory.CreateDecoderFromFileName(
                    filePath,
                    DesiredAccess.Read,
                    DecodeMetadataCacheOption.OnDemand);

            return(LoadFromDecoder(device, factory, bitmapDecoder));
        }
Example #3
0
        private void CreateFactories()
        {
            //reuse factories except for random cases
            if (random.NextDouble() < 0.5)
            {
                lock (sharedSyncObject)
                {
                    if (sharedD2DFactory == null)
                    {
                        // Create the D2D Factory
                        sharedD2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

                        // Create the DWrite Factory
                        sharedDwriteFactory = DWriteFactory.CreateFactory();

                        // Create the WIC Factory
                        sharedWicFactory = ImagingFactory.Create();

                        Debug.Assert(sharedD2DFactory.NativeInterface != IntPtr.Zero);
                        Debug.Assert(sharedDwriteFactory.NativeInterface != IntPtr.Zero);
                        Debug.Assert(sharedWicFactory.NativeInterface != IntPtr.Zero);
                    }
                    sharedRefCount++;
                }
                d2DFactory    = sharedD2DFactory;
                dwriteFactory = sharedDwriteFactory;
                wicFactory    = sharedWicFactory;
                Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero);
            }
            else
            {
                // Create the D2D Factory
                d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded);

                // Create the DWrite Factory
                dwriteFactory = DWriteFactory.CreateFactory();

                // Create the WIC Factory
                wicFactory = ImagingFactory.Create();
                Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero);
            }
        }
Example #4
0
        private void LoadDeviceIndependentResource()
        {
            // Create the D2D Factory
            // This really needs to be set to type MultiThreaded if rendering is to be performed by multiple threads,
            // such as if used in a control similar to DirectControl sample control where rendering is done by a dedicated render thread,
            // especially if multiple such controls are used in one application, but also when multiple applications use D2D Factories.
            //
            // In this sample - SingleThreaded type is used because rendering is only done by the main/UI thread and only when required
            // (when the surface gets invalidated) making the risk of synchronization problems - quite low.
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded);

            // Create the DWrite Factory
            dwriteFactory = DWriteFactory.CreateFactory();

            // Create the WIC Factory
            wicFactory = ImagingFactory.Create();

            TextBoxStroke = d2dFactory.CreateStrokeStyle(
                new StrokeStyleProperties(
                    CapStyle.Flat, CapStyle.Flat, CapStyle.Round,
                    LineJoin.Miter, 5.0f, DashStyle.Dash, 3f),
                null);
        }
Example #5
0
        private void CreateDeviceIndependentResources()
        {
            // Create the D2D Factory
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

            // Create the DWrite Factory
            dwriteFactory = DWriteFactory.CreateFactory();

            wicFactory = ImagingFactory.Create();

            string text = "Inline Object * Sample";

            textFormat = dwriteFactory.CreateTextFormat("Gabriola", 72);

            textFormat.TextAlignment      = DWrite.TextAlignment.Center;
            textFormat.ParagraphAlignment = DWrite.ParagraphAlignment.Center;

            textLayout = dwriteFactory.CreateTextLayout(
                text,
                textFormat,
                (float)host.ActualWidth,
                (float)host.ActualHeight);
        }
Example #6
0
        void CreateDeviceIndependentResources()
        {
            string msc_fontName = "Verdana";
            float  msc_fontSize = 50;

            string fps_fontName = "Courier New";
            float  fps_fontSize = 12;

            GeometrySink spSink;

            // Create D2D factory
            d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

            // Create WIC factory
            imagingFactory = ImagingFactory.Create();

            // Create DWrite factory
            dWriteFactory = DWriteFactory.CreateFactory();

            // Create DWrite text format object
            textFormat = dWriteFactory.CreateTextFormat(
                msc_fontName,
                msc_fontSize);

            textFormat.TextAlignment      = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.TextAlignment.Center;
            textFormat.ParagraphAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.ParagraphAlignment.Center;


            // Create DWrite text format object
            textFormatFps = dWriteFactory.CreateTextFormat(
                fps_fontName,
                fps_fontSize);

            textFormatFps.TextAlignment      = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.TextAlignment.Leading;
            textFormatFps.ParagraphAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.ParagraphAlignment.Near;

            // Create the path geometry.
            pathGeometry = d2DFactory.CreatePathGeometry();

            // Write to the path geometry using the geometry sink. We are going to create an
            // hour glass.
            spSink = pathGeometry.Open();

            spSink.SetFillMode(Microsoft.WindowsAPICodePack.DirectX.Direct2D1.FillMode.Alternate);

            spSink.BeginFigure(
                new Point2F(0, 0),
                FigureBegin.Filled
                );

            spSink.AddLine(new Point2F(200, 0));

            spSink.AddBezier(
                new BezierSegment(
                    new Point2F(150, 50),
                    new Point2F(150, 150),
                    new Point2F(200, 200)
                    ));

            spSink.AddLine(
                new Point2F(0,
                            200)
                );

            spSink.AddBezier(
                new BezierSegment(
                    new Point2F(50, 150),
                    new Point2F(50, 50),
                    new Point2F(0, 0)
                    ));

            spSink.EndFigure(
                FigureEnd.Closed
                );

            spSink.Close(
                );
        }