Ejemplo n.º 1
0
        public TileGameWindow(string title, int width, int height, bool fullscreen)
            : base(title, width, height, fullscreen)
        {
            this.m_Factory = new Factory();

            RenderTargetProperties rtProperties = new RenderTargetProperties
            {
                PixelFormat = new SlimDXPixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
            };

            WindowRenderTargetProperties properties = new WindowRenderTargetProperties
            {
                Handle    = FormObject.Handle,
                PixelSize = new Size(width, height)
            };

            this.m_RenderTarget = new WindowRenderTarget(this.m_Factory, rtProperties, properties);

            this.m_DebugBrush = new SolidColorBrush(this.m_RenderTarget, new Color4(1.0f, 1.0f, 1.0f, 0.0f));

            this.m_PlayerSprites = LoadBitmap(Application.StartupPath + "\\Robot.png");
            this.m_Player        = new Player
            {
                PositionX = 4,
                PositionY = 8
            };

            this.InitalizeTileGameWorld();
        }
Ejemplo n.º 2
0
        //============================================================
        // <T>设置处理。</T>
        //============================================================
        public void Setup()
        {
            // 设置属性
            WindowRenderTargetProperties properties = new WindowRenderTargetProperties();

            properties.Handle    = _handle;
            properties.PixelSize = new Size(_size.Width, _size.Height);
            // 创建目标
            _target = new WindowRenderTarget(_factory, properties);
            _target.AntialiasMode = AntialiasMode.PerPrimitive;
        }
Ejemplo n.º 3
0
        //============================================================
        // <T>设置处理。</T>
        //============================================================
        public void Setup()
        {
            // 设置属性
            WindowRenderTargetProperties properties = new WindowRenderTargetProperties();

            properties.Handle    = _handle;
            properties.PixelSize = new Size(_size.Width, _size.Height);
            // 创建工厂
            _factory = new Factory();
            // 创建目标
            _target = new WindowRenderTarget(_factory, properties);
        }
Ejemplo n.º 4
0
        public void Using_DirectWrite()
        {
            Device device;
            SwapChain swapChain;
            RenderTargetView renderTarget;

            EmptyWindow.CreateDeviceSwapChainAndRenderTarget(mForm, out device, out swapChain, out renderTarget);

            var direct2dfactory = new Direct2DFactory();
            var directWriteFactory = new DirectWriteFactory();

            var properties = new WindowRenderTargetProperties { Handle = mForm.Handle, PixelSize = mForm.ClientSize };
            var windowRenderTarget = new WindowRenderTarget(direct2dfactory, properties);
            var brush = new SolidColorBrush(windowRenderTarget, Color.Black);

            var textFormat = new TextFormat(directWriteFactory, "Gabriola",
                FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 72.0f, "en-us")
            {
                TextAlignment = TextAlignment.Center,
                ParagraphAlignment = ParagraphAlignment.Center
            };

            Application.Idle +=
                delegate
                {
                    device.ClearRenderTargetView(renderTarget, new Color4(1, 0, 0));

                    if (!windowRenderTarget.IsOccluded)
                    {
                        windowRenderTarget.BeginDraw();
                        windowRenderTarget.Transform = Matrix3x2.Identity;
                        windowRenderTarget.Clear(Color.White);

                        windowRenderTarget.DrawText("Hello World using DirectWrite!", textFormat, mForm.ClientRectangle, brush);

                        windowRenderTarget.EndDraw();
                    }

                    swapChain.Present(0, PresentFlags.None);

                    Application.DoEvents();
                };

            Application.Run(mForm);
        }