Beispiel #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();
        }
Beispiel #2
0
        private void initializeGraphics()
        {
            factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, D2D.DebugLevel.None);

            //Create the render target
            renderTarget = new D2D.WindowRenderTarget(factory, new D2D.WindowRenderTargetProperties()
            {
                Handle         = this.Handle,
                PixelSize      = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
                new D2D.GradientStop()
                {
                    Position = 0f, Color = new Color4(Color.White)
                },
                new D2D.GradientStop()
                {
                    Position = 1f, Color = new Color4(Color.White)
                }
            };
            backBrushGradient = new D2D.GradientStopCollection(renderTarget, gradientStops);
            backBrushEx       = new D2D.LinearGradientBrush(renderTarget, backBrushGradient, new D2D.LinearGradientBrushProperties()
            {
                StartPoint = new PointF(0, this.Height), EndPoint = new PointF(0, 0)
            });

            //Update initialization flag
            this.FinishedInit = true;
        }
        /// <summary>
        ///     デバイスを初期化します.
        /// </summary>
        public new void Load()
        {
            base.Load(false, D3D.DeviceCreationFlags.BgraSupport, DeviceCreationFlags.BgraSupport);

            //ラスタライザの設定を上書き
            var blendDesc = new D3D.BlendStateDescription();

            blendDesc.AlphaToCoverageEnable  = true; // Alpha to Coverage を有効にする
            blendDesc.IndependentBlendEnable = false;
            for (int i = 0; i < blendDesc.RenderTargets.Length; i++)
            {
                blendDesc.RenderTargets[i].BlendEnable           = true;
                blendDesc.RenderTargets[i].SourceBlend           = D3D.BlendOption.SourceAlpha;
                blendDesc.RenderTargets[i].DestinationBlend      = D3D.BlendOption.InverseSourceAlpha;
                blendDesc.RenderTargets[i].BlendOperation        = D3D.BlendOperation.Add;
                blendDesc.RenderTargets[i].SourceBlendAlpha      = D3D.BlendOption.One;
                blendDesc.RenderTargets[i].DestinationBlendAlpha = D3D.BlendOption.One; // ここを1にしないとアルファの合成が変
                blendDesc.RenderTargets[i].BlendOperationAlpha   = D3D.BlendOperation.Add;
                blendDesc.RenderTargets[i].RenderTargetWriteMask = D3D.ColorWriteMaskFlags.All;
            }

            customBlendState = Context.OutputMerger.BlendState = D3D.BlendState.FromDescription(Device, blendDesc);

            d2dFactory = new D2D.Factory(D2D.FactoryType.Multithreaded);
            dwFactory  = new DW.Factory(DW.FactoryType.Shared);
        }
Beispiel #4
0
 public DWOutlinedText(D2D.Factory d2dFactory, DW.Factory dwFactory, string fontfile, int fontFaceIndex,
                       DW.FontFaceType fontFaceType)
 {
     _d2DFactory    = d2dFactory;
     _dwFactory     = dwFactory;
     _fontFile      = _dwFactory.CreateFontFileReference(fontfile);
     _fontFaceIndex = fontFaceIndex;
     _fontFaceType  = fontFaceType;
 }
Beispiel #5
0
        public D2DInteropHandler(RenderManager manager)
        {
            Manager = manager;
            #if DEBUG
            D3DDevice10 = new D3D101.Device1(manager.DXGIAdapter, D3D10.DriverType.Hardware, D3D10.DeviceCreationFlags.BgraSupport | D3D10.DeviceCreationFlags.Debug, D3D101.FeatureLevel.Level_10_0);
            #else
            D3DDevice10 = new D3D101.Device1(D3D10.DriverType.Hardware, D3D10.DeviceCreationFlags.BgraSupport, D3D101.FeatureLevel.Level_10_0);
            #endif
            D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);

            DWFactory = new DW.Factory(DW.FactoryType.Shared);
        }
Beispiel #6
0
 public d2dengine(Control container, List <gameobject> theList)
 {
     ToDraw                = theList;
     targetControl         = container;
     debugLevel            = DebugLevel.None;
     d2dFactory            = new SlimDX.Direct2D.Factory(SlimDX.Direct2D.FactoryType.Multithreaded, debugLevel);
     wrtFactory            = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Shared);
     d2dWindowRenderTarget = new WindowRenderTarget(d2dFactory, new WindowRenderTargetProperties()
     {
         Handle         = targetControl.Handle,
         PixelSize      = targetControl.Size,
         PresentOptions = PresentOptions.Immediately
     });
 }
        public DeviceContext10_1(DeviceSettings10_1 settings)
        {
            m_settings = settings;

            Direct3DFactory = new Factory1();
         
            /* Create a Direct3D device using our passed settings */
            Device = new SlimDX.Direct3D10_1.Device1(Direct3DFactory.GetAdapter(m_settings.AdapterOrdinal),
                                                       DriverType.Hardware,
                                                       settings.CreationFlags,
                                                       FeatureLevel.Level_10_0);

            /* Create a Direct2D factory while we are at it...*/
            Direct2DFactory = new SlimDX.Direct2D.Factory(FactoryType.Multithreaded);

            MakeBothSidesRendered();
        }
Beispiel #8
0
        private bool InitDirect2D()
        {
            try {
                var factory = new SlimDX.Direct2D.Factory(FactoryType.SingleThreaded);

                _dxWRT = new WindowRenderTarget(factory, new WindowRenderTargetProperties {
                    Handle         = Window.Handle,
                    PixelSize      = Window.ClientSize,
                    PresentOptions = PresentOptions.Immediately
                });
                Util.ReleaseCom(ref factory);
                _progressUpdate = new ProgressUpdate(_dxWRT);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }
Beispiel #9
0
        public void Render(SlimDX.Direct2D.Factory factory, SlimDX.DirectWrite.Factory dwFactory, RenderTarget renderTarget)
        {
            if (this.brush == null)
            {
                brush     = new SolidColorBrush(renderTarget, new Color4(1.0f, 1.0f, 1.0f));
                txtFormat = dwFactory.CreateTextFormat("lcd phone", FontWeight.Regular, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 60, "en-us");
            }

            SizeF newWindowSize = renderTarget.Size;

            if (windowSize == null || !windowSize.Equals(newWindowSize))
            {
                windowSize = newWindowSize;
                float centerX = windowSize.Width / 2;
                rect = new RectangleF(new PointF(centerX + posOffset.X, posOffset.Y), textLayoutSize);
            }

            renderTarget.DrawText(val.ToString(), txtFormat, rect, brush);
        }
Beispiel #10
0
        public TextRenderTarget(RenderTargetTexture renderTargetTexture)
        {
            var surface = renderTargetTexture.AsSurface();
            var factory2D = new SlimDX.Direct2D.Factory(SlimDX.Direct2D.FactoryType.SingleThreaded);

            var renderTargetProperties = new RenderTargetProperties
            {
                PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied),
                Usage = RenderTargetUsage.None,
                HorizontalDpi = 96,
                VerticalDpi = 96,
                MinimumFeatureLevel = FeatureLevel.Direct3D10,
                Type = RenderTargetType.Default
            };

            mRenderTarget = RenderTarget.FromDXGI(factory2D, surface,
                renderTargetProperties);

            mBrush = new SolidColorBrush(mRenderTarget, new Color4(1, 1, 1));

            CreateTextFormat();
        }
        // Entlädt alle graphicken
        private void UnloadGraphics()
        {
            if (m_backBrushEx != null)
            {
                m_backBrushEx.Dispose();
            }
            if (m_backBrushGradient != null)
            {
                m_backBrushGradient.Dispose();
            }
            if (m_renderTarget != null)
            {
                m_renderTarget.Dispose();
            }
            if (m_factory != null)
            {
                m_factory.Dispose();
            }

            m_backBrushEx       = null;
            m_backBrushGradient = null;
            m_renderTarget      = null;
            m_factory           = null;
        }
Beispiel #12
0
        private bool InitDirect2D()
        {
            try {
                var factory = new SlimDX.Direct2D.Factory(FactoryType.SingleThreaded);

                _dxWRT = new WindowRenderTarget(factory, new WindowRenderTargetProperties {
                    Handle = Window.Handle,
                    PixelSize = Window.ClientSize,
                    PresentOptions = PresentOptions.Immediately
                });
                Util.ReleaseCom(ref factory);
                _progressUpdate = new ProgressUpdate(_dxWRT);

            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return false;
            }
            return true;
        }
Beispiel #13
0
        static void Main()
        {
            var states = new Stack <State>();

            var str = "L";

            {
                var tbl = new Dictionary <char, string>();

                tbl.Add('L', "|-S!L!Y");
                tbl.Add('S', "[F[FF-YS]F)G]+");
                tbl.Add('Y', "--[F-)<F-FG]-");
                tbl.Add('G', "FGF[Y+>F]+Y");

                for (var i = 0; i < 12; i++)
                {
                    str = Rewrite(tbl, str);
                }
            }

            var sizeGrowth  = -1.359672;
            var angleGrowth = -0.138235;

            State state;

            var lines = new List <Point>();

            var pen = new Pen(Brushes.Black, 0.25F);

            var initAngle = -3963.7485;

            Action buildLines = () =>
            {
                lines.Clear();

                state = new State()
                {
                    x     = 400,
                    y     = 400,
                    dir   = 0,
                    size  = 14.11,
                    angle = initAngle
                };

                foreach (var elt in str)
                {
                    if (elt == 'F')
                    {
                        var new_x = state.x + state.size * Math.Cos(state.dir * Math.PI / 180.0);
                        var new_y = state.y + state.size * Math.Sin(state.dir * Math.PI / 180.0);

                        lines.Add(new Point((int)state.x, (int)state.y));
                        lines.Add(new Point((int)new_x, (int)new_y));

                        state.x = new_x;
                        state.y = new_y;
                    }
                    else if (elt == '+')
                    {
                        state.dir += state.angle;
                    }

                    else if (elt == '-')
                    {
                        state.dir -= state.angle;
                    }

                    else if (elt == '>')
                    {
                        state.size *= (1.0 - sizeGrowth);
                    }

                    else if (elt == '<')
                    {
                        state.size *= (1.0 + sizeGrowth);
                    }

                    else if (elt == ')')
                    {
                        state.angle *= (1 + angleGrowth);
                    }

                    else if (elt == '(')
                    {
                        state.angle *= (1 - angleGrowth);
                    }

                    else if (elt == '[')
                    {
                        states.Push(state.Clone());
                    }

                    else if (elt == ']')
                    {
                        state = states.Pop();
                    }

                    else if (elt == '!')
                    {
                        state.angle *= -1.0;
                    }

                    else if (elt == '|')
                    {
                        state.dir += 180.0;
                    }
                }
            };


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new RenderForm("LSys - Q/A: angleGrowth - W/S: initAngle");

            var swapChainDescription = new SwapChainDescription()
            {
                BufferCount       = 2,
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = form.Handle,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard
            };

            SlimDX.Direct3D11.Device device;
            SwapChain swapChain;

            SlimDX.Direct3D11.Device.CreateWithSwapChain(
                DriverType.Hardware,
                DeviceCreationFlags.BgraSupport,
                swapChainDescription,
                out device,
                out swapChain
                );

            Surface backBuffer = Surface.FromSwapChain(swapChain, 0);

            RenderTarget renderTarget;

            using (var factory = new SlimDX.Direct2D.Factory())
            {
                var dpi = factory.DesktopDpi;

                Console.WriteLine("dpi {0} {1}", dpi.Width, dpi.Height);

                renderTarget = RenderTarget.FromDXGI(
                    factory,
                    backBuffer,
                    new RenderTargetProperties()
                {
                    HorizontalDpi = dpi.Width,
                    VerticalDpi   = dpi.Height,

                    MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
                    PixelFormat         = new PixelFormat(Format.Unknown, AlphaMode.Ignore),
                    Type  = RenderTargetType.Default,
                    Usage = RenderTargetUsage.None
                });
            }

            using (var factory = swapChain.GetParent <SlimDX.DXGI.Factory>())
                factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);

            form.KeyDown += (sender, args) =>
            {
                if (args.Alt && args.KeyCode == Keys.Enter)
                {
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;
                }

                if (args.KeyCode == Keys.Q)
                {
                    angleGrowth += 0.0001;
                }

                if (args.KeyCode == Keys.A)
                {
                    angleGrowth -= 0.0001;
                }

                if (args.KeyCode == Keys.W)
                {
                    initAngle += 0.2;
                }

                if (args.KeyCode == Keys.S)
                {
                    initAngle -= 0.2;
                }

                buildLines();
            };

            form.Size = new Size(800, 600);

            Console.WriteLine("renderTarget.Size {0} {1}", renderTarget.Size.Width, renderTarget.Size.Height);

            // form.AutoSizeMode = AutoSizeMode.GrowAndShrink;

            // form.AutoScaleDimensions = new SizeF(2000, 800);

            buildLines();

            MessagePump.Run(
                form,
                () =>
            {
                renderTarget.BeginDraw();
                renderTarget.Transform = Matrix3x2.Identity;
                renderTarget.Clear(Color.Black);

                using (var brush = new SolidColorBrush(renderTarget, new Color4(Color.White)))
                {
                    for (var i = 0; i < lines.Count; i += 2)
                    {
                        var a = lines[i];
                        var b = lines[i + 1];

                        renderTarget.DrawLine(brush, a.X, a.Y, b.X, b.Y, 0.1f);
                    }
                }

                renderTarget.EndDraw();

                swapChain.Present(0, PresentFlags.None);
            });

            renderTarget.Dispose();
            swapChain.Dispose();
            device.Dispose();
        }
Beispiel #14
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);
        }
        private void initializeGraphics()
        {
            factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, D2D.DebugLevel.None);

            //Create the render target
            renderTarget = new D2D.WindowRenderTarget(factory, new D2D.WindowRenderTargetProperties()
            {
                Handle = this.Handle,
                PixelSize = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
               new D2D.GradientStop(){ Position = 0f, Color = new Color4(Color.White) },
                new D2D.GradientStop(){ Position = 1f, Color = new Color4(Color.White) }
            };
            backBrushGradient = new D2D.GradientStopCollection(renderTarget, gradientStops);
            backBrushEx = new D2D.LinearGradientBrush(renderTarget, backBrushGradient, new D2D.LinearGradientBrushProperties() { StartPoint = new PointF(0, this.Height), EndPoint = new PointF(0, 0) });

            //Update initialization flag
            this.FinishedInit = true;
        }
        // Ladet alle Graphischen ressoursen
        private void InitializeGraphics()
        {
            //Get requested debug level
            D2D.DebugLevel debugLevel = D2D.DebugLevel.None;
            if (m_debugMode)
            {
                debugLevel = D2D.DebugLevel.Error;
            }

            //Create factory object
            m_factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, debugLevel);

            //Create the render target
            m_renderTarget = new D2D.WindowRenderTarget(m_factory, new D2D.WindowRenderTargetProperties()
            {
                Handle         = this.Handle,
                PixelSize      = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
                new D2D.GradientStop()
                {
                    Position = 0f, Color = new Color4(Color.LightGray)
                },
                new D2D.GradientStop()
                {
                    Position = 1f, Color = new Color4(Color.Black)
                }
            };
            m_backBrushGradient = new D2D.GradientStopCollection(m_renderTarget, gradientStops);
            m_backBrushEx       = new D2D.LinearGradientBrush(
                m_renderTarget,
                m_backBrushGradient,
                new D2D.LinearGradientBrushProperties()
            {
                StartPoint = new PointF(0, this.Height),
                EndPoint   = new PointF(0, 0)
            });

            //Create gdi backbrush
            if (m_backBrushGdi != null)
            {
                m_backBrushGdi.Dispose();
            }
            m_backBrushGdi = new LinearGradientBrush(
                new Point(0, this.Height),
                new Point(0, 0),
                Color.LightGray,
                Color.LightSteelBlue);

            //Load the bitmap
            level.Backgroundgdi = Resources.Resources.SpaceBackground1;
            level.Background    = LoadBitmap(level.Backgroundgdi);

            spaceshipBitmapGDI         = Resources.Resources.GreenSpaceShip;
            spaceShipBitmap            = LoadBitmap(spaceshipBitmapGDI);
            _Player                    = new PlayerShip(spaceShipBitmap);
            projektileBitmapGdi        = Resources.Resources.greenProjectile;
            projektileBitmap           = LoadBitmap(projektileBitmapGdi);
            projektileHostileBitmapGdi = Resources.Resources.greenprojectile1;
            projektileHostileBitmap    = LoadBitmap(projektileHostileBitmapGdi);
            level.Backgroundlvl1       = LoadBitmap(Resources.Resources.SpaceBackground1);
            level.Backgroundlvl2       = LoadBitmap(Resources.Resources.sewer);
            level.BackgroundGameOver   = LoadBitmap(Resources.Resources.GameOver);
            level.BackgroundNextLevel  = LoadBitmap(Resources.Resources.NextLevel);
            enenyShipBitmap            = LoadBitmap(Resources.Resources.cartoonship_red);
            //Update initialization flag
            m_initialized = true;
        }
Beispiel #17
0
        public void Init()
        {
            #region init_gfx
            var form = new RenderForm("MIDITrailer");

            var factory = new FactoryD2D();
            SizeF dpi = factory.DesktopDpi;
            // Create swap chain description
            var swapChainDesc = new SwapChainDescription()
            {
                BufferCount = 2,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = form.Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription((int)(GFXResources.Bounds.Width * (dpi.Width / 96f)), (int)(GFXResources.Bounds.Height * (dpi.Height / 96f)), new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard,
            };

            Device device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, out device, out swapChain);

            Surface backBuffer = Surface.FromSwapChain(swapChain, 0);

            renderTarget = RenderTarget.FromDXGI(factory, backBuffer, new RenderTargetProperties()
            {
                HorizontalDpi = dpi.Width,
                VerticalDpi = dpi.Height,
                MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
                PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore),
                Type = RenderTargetType.Default,
                Usage = RenderTargetUsage.None
            });
            factory.Dispose();

            // Freaking antialiasing lagging up my programs
            renderTarget.AntialiasMode = AntialiasMode.Aliased;

            using (var DXGIFactory = swapChain.GetParent<FactoryDXGI>())
                DXGIFactory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);

            form.Size = new Size(Bounds.Width, Bounds.Height);
            form.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            #endregion

            GFXResources.Init(renderTarget);

            #region init_timers
            eventTimer = new Timer(15) { Enabled = true };
            eventTimer.Elapsed += delegate
            {
                lock (backlog)
                {
                    while (backlog.Any() && backlog.First().StartTime <= DateTime.Now)
                    {
                        Event ev = backlog.Dequeue();
                        ev.Method();
                    }
                }
            };
            #endregion

            form.KeyDown += (o, e) =>
            {
                Keys key = e.KeyCode;
                switch (key)
                {
                    case Keys.F11:
                        swapChain.IsFullScreen = !swapChain.IsFullScreen;
                        break;
                    case Keys.F:
                        Fancy = !Fancy;
                        UserFancy = !UserFancy;
                        break;
                    case Keys.Up:
                        Delay += 100;
                        notes.Clear();
                        backlog.Clear();
                        break;
                    case Keys.Down:
                        if (Delay >= 100)
                        {
                            Delay -= 100;
                            notes.Clear();
                            backlog.Clear();
                        }
                        break;
                }
            };

            Thread t = new Thread(Load);
            t.Start();

            MessagePump.Run(form, () =>
            {
                UpdateNotePositions();
                UpdateRenderer();
                Paint(renderTarget);
                swapChain.Present(1, PresentFlags.None);
            });

            renderTarget.Dispose();
            swapChain.Dispose();
            device.Dispose();
            outDevice.Close();
            outDevice.Dispose();
            sequencer.Stop();
            sequencer.Dispose();
            sequence?.Dispose();
        }
        //Ladet alle graphicken
        private void InitializeGraphics()
        {
            //Get requested debug level
            D2D.DebugLevel debugLevel = D2D.DebugLevel.None;
            if (m_debugMode)
            {
                debugLevel = D2D.DebugLevel.Error;
            }

            //Create factory object
            m_factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, debugLevel);
            //  m_factoryText = new SlimDX.DirectWrite.Factory();
            //Create the render target
            m_renderTarget = new D2D.WindowRenderTarget(m_factory, new D2D.WindowRenderTargetProperties()
            {
                Handle         = this.Handle,
                PixelSize      = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
                new D2D.GradientStop()
                {
                    Position = 0f, Color = new Color4(Color.LightGray)
                },
                new D2D.GradientStop()
                {
                    Position = 1f, Color = new Color4(Color.Black)
                }
            };
            m_backBrushGradient = new D2D.GradientStopCollection(m_renderTarget, gradientStops);
            m_backBrushEx       = new D2D.LinearGradientBrush(
                m_renderTarget,
                m_backBrushGradient,
                new D2D.LinearGradientBrushProperties()
            {
                StartPoint = new PointF(0, this.Height),
                EndPoint   = new PointF(0, 0)
            });

            //Create gdi backbrush
            if (m_backBrushGdi != null)
            {
                m_backBrushGdi.Dispose();
            }
            m_backBrushGdi = new LinearGradientBrush(
                new Point(0, this.Height),
                new Point(0, 0),
                Color.LightGray,
                Color.LightSteelBlue);

            //Load the bitmap

            backGroundBitmap = LoadBitmap(Resources.Resource.skyline);
            groundBitmap     = LoadBitmap(Resources.Resource.ground);
            pipeLowerBitmap  = LoadBitmap(Resources.Resource.pipe_up);
            pipeUperBitmap   = LoadBitmap(Resources.Resource.pipe_down);
            birdBitmap       = LoadBitmap(Resources.Resource.bird_one);
            //Update initialization flag
            m_initialized = true;
        }
Beispiel #19
0
        public void Init()
        {
            #region init_gfx
            Form = new RenderForm("Kazedan");
            var   factory = new FactoryD2D();
            SizeF dpi     = factory.DesktopDpi;

            var swapChainDesc = new SwapChainDescription()
            {
                BufferCount       = 2,
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = Form.Handle,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription((int)(GFXResources.Bounds.Width * (dpi.Width / 96f)), (int)(GFXResources.Bounds.Height * (dpi.Height / 96f)), new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard,
            };

            Device    device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, out device, out swapChain);

            Surface backBuffer = Surface.FromSwapChain(swapChain, 0);

            renderTarget = RenderTarget.FromDXGI(factory, backBuffer, new RenderTargetProperties()
            {
                HorizontalDpi       = dpi.Width,
                VerticalDpi         = dpi.Height,
                MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
                PixelFormat         = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore),
                Type  = RenderTargetType.Default,
                Usage = RenderTargetUsage.None
            });
            factory.Dispose();

            // Freaking antialiasing lagging up my programs
            renderTarget.AntialiasMode     = AntialiasMode.Aliased;
            renderTarget.TextAntialiasMode = TextAntialiasMode.Grayscale;

            using (var DXGIFactory = swapChain.GetParent <FactoryDXGI>())
                DXGIFactory.SetWindowAssociation(Form.Handle, WindowAssociationFlags.IgnoreAltEnter);

            Form.ClientSize   = GFXResources.Bounds;
            Form.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            Form.Icon         = Properties.Resources.KazedanIcon;
            #endregion

            GFXResources.Init(renderTarget);

            Form.KeyDown += (o, e) =>
            {
                Keys key = e.KeyCode;
                switch (key)
                {
                case Keys.F11:
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;
                    break;

                case Keys.F:
                    Sequencer.NoteManager.UserEnabledFancy = !Sequencer.NoteManager.UserEnabledFancy;
                    Sequencer.NoteManager.RenderFancy      = Sequencer.NoteManager.UserEnabledFancy;
                    break;

                case Keys.Up:
                    Sequencer.Delay += 100;
                    Sequencer.Reset();
                    break;

                case Keys.Down:
                    if (Sequencer.Delay >= 100)
                    {
                        Sequencer.Delay -= 100;
                        Sequencer.Reset();
                    }
                    break;

                case Keys.Left:
                    if (GFXResources.NoteOffset > 0)
                    {
                        GFXResources.NoteOffset--;
                    }
                    break;

                case Keys.Right:
                    if (GFXResources.NoteOffset < 128 - GFXResources.NoteCount)
                    {
                        GFXResources.NoteOffset++;
                    }
                    break;

                case Keys.D:
                    Sequencer.ShowDebug = !Sequencer.ShowDebug;
                    break;

                case Keys.Space:
                    if (Sequencer.Stopped)
                    {
                        Sequencer.Start();
                    }
                    else
                    {
                        Sequencer.Stop();
                    }
                    break;
                }
            };

            // Start loading thread
            Thread loadThread = new Thread(Load);
            loadThread.Start();

            // Show controller window
            Thread controlThread = new Thread(() =>
            {
                loadThread.Join();
                Application.EnableVisualStyles();
                ControlForm = new KZControl(Sequencer);
                Application.Run(ControlForm);
            });
            controlThread.SetApartmentState(ApartmentState.STA);
            controlThread.Start();

            // Make sure the control form closes when the main form does
            Form.Disposed += (o, e) =>
            {
                ControlForm?.BeginInvoke((MethodInvoker) delegate
                {
                    ControlForm.Close();
                });
            };

            MessagePump.Run(Form, () =>
            {
                // Do sequencer tick
                if (!Sequencer.Stopped)
                {
                    Sequencer.UpdateNotePositions();
                    Sequencer.UpdateRenderer();
                }
                Paint(renderTarget);

                // Calculate profiling information
                long tick = Environment.TickCount;
                if (tick - LastSample >= SampleRate)
                {
                    Elapsed    = tick - LastTick;
                    LastSample = tick;
                }
                LastTick = tick;
                swapChain.Present(1, PresentFlags.None);
            });

            renderTarget.Dispose();
            swapChain.Dispose();
            device.Dispose();
            Sequencer.Dispose();
        }
Beispiel #20
0
        public void Init()
        {
            #region init_gfx
            Form = new RenderForm("Kazedan");
            var factory = new FactoryD2D();
            SizeF dpi = factory.DesktopDpi;

            var swapChainDesc = new SwapChainDescription()
            {
                BufferCount = 2,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = Form.Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription((int)(GFXResources.Bounds.Width * (dpi.Width / 96f)), (int)(GFXResources.Bounds.Height * (dpi.Height / 96f)), new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard,
            };

            Device device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, out device, out swapChain);

            Surface backBuffer = Surface.FromSwapChain(swapChain, 0);

            renderTarget = RenderTarget.FromDXGI(factory, backBuffer, new RenderTargetProperties()
            {
                HorizontalDpi = dpi.Width,
                VerticalDpi = dpi.Height,
                MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default,
                PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore),
                Type = RenderTargetType.Default,
                Usage = RenderTargetUsage.None
            });
            factory.Dispose();

            // Freaking antialiasing lagging up my programs
            renderTarget.AntialiasMode = AntialiasMode.Aliased;
            renderTarget.TextAntialiasMode = TextAntialiasMode.Grayscale;
            
            using (var DXGIFactory = swapChain.GetParent<FactoryDXGI>())
                DXGIFactory.SetWindowAssociation(Form.Handle, WindowAssociationFlags.IgnoreAltEnter);

            Form.ClientSize = GFXResources.Bounds;
            Form.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            Form.Icon = Properties.Resources.KazedanIcon;
            #endregion

            GFXResources.Init(renderTarget);

            Form.KeyDown += (o, e) =>
            {
                Keys key = e.KeyCode;
                switch (key)
                {
                    case Keys.F11:
                        swapChain.IsFullScreen = !swapChain.IsFullScreen;
                        break;
                    case Keys.F:
                        Sequencer.NoteManager.UserEnabledFancy = !Sequencer.NoteManager.UserEnabledFancy;
                        Sequencer.NoteManager.RenderFancy = Sequencer.NoteManager.UserEnabledFancy;
                        break;
                    case Keys.Up:
                        Sequencer.Delay += 100;
                        Sequencer.Reset();
                        break;
                    case Keys.Down:
                        if (Sequencer.Delay >= 100)
                        {
                            Sequencer.Delay -= 100;
                            Sequencer.Reset();
                        }
                        break;
                    case Keys.Left:
                        if (GFXResources.NoteOffset > 0)
                            GFXResources.NoteOffset--;
                        break;
                    case Keys.Right:
                        if (GFXResources.NoteOffset < 128 - GFXResources.NoteCount)
                            GFXResources.NoteOffset++;
                        break;
                    case Keys.D:
                        Sequencer.ShowDebug = !Sequencer.ShowDebug;
                        break;
                    case Keys.Space:
                        if (Sequencer.Stopped)
                            Sequencer.Start();
                        else
                            Sequencer.Stop();
                        break;
                }
            };

            Thread loadThread = new Thread(Load);
            loadThread.Start();

            Thread controlThread = new Thread(() =>
            {
                loadThread.Join();
                Application.EnableVisualStyles();
                Application.Run(new KZControl(Sequencer));
            });
            controlThread.SetApartmentState(ApartmentState.STA);
            controlThread.Start();

            MessagePump.Run(Form, () =>
            {
                // Do sequencer tick
                if (!Sequencer.Stopped)
                {
                    Sequencer.UpdateNotePositions();
                    Sequencer.UpdateRenderer();
                }
                Paint(renderTarget);

                // Calculate profiling information
                long tick = Environment.TickCount;
                if (tick - LastSample >= SampleRate)
                {
                    Elapsed = tick - LastTick;
                    LastSample = tick;
                }
                LastTick = tick;
                swapChain.Present(1, PresentFlags.None);
            });

            renderTarget.Dispose();
            swapChain.Dispose();
            device.Dispose();
            Sequencer.Dispose();
        }