Example #1
0
        public Engine(EngineSetup setup = null)
        {
            XmlConfigurator.Configure();

            _loaded = false;
            _setup  = new EngineSetup();
            if (setup != null)
            {
                _setup = setup;
            }
            _gEngine = this;

            var d3d         = new Direct3D();
            var enumeration = new DeviceEnumeration(d3d);

            if (enumeration.ShowDialog() != DialogResult.OK)
            {
                ReleaseCom(d3d);
                return;
            }


            Window = new FpsForm {
                Name            = "WindowClass",
                Text            = _setup.Name,
                FormBorderStyle = enumeration.Windowed ? FormBorderStyle.FixedSingle : FormBorderStyle.None,
                Size            = new Size(800, 600)
            };

            var pp = new PresentParameters {
                BackBufferWidth              = enumeration.SelectedDisplayMode.Width,
                BackBufferHeight             = enumeration.SelectedDisplayMode.Height,
                BackBufferFormat             = enumeration.SelectedDisplayMode.Format,
                BackBufferCount              = _setup.TotalBackBuffers,
                SwapEffect                   = SwapEffect.Discard,
                DeviceWindowHandle           = Window.Handle,
                Windowed                     = enumeration.Windowed,
                EnableAutoDepthStencil       = true,
                AutoDepthStencilFormat       = Format.D24S8,
                FullScreenRefreshRateInHertz = enumeration.SelectedDisplayMode.RefreshRate,
                PresentationInterval         = enumeration.VSync ? PresentInterval.Default :  PresentInterval.Immediate,
                Multisample                  = MultisampleType.None,
                MultisampleQuality           = 0,
                PresentFlags                 = PresentFlags.None
            };

            enumeration.Dispose();

            _device = new Device(d3d, 0, DeviceType.Hardware, Window.Handle, CreateFlags.MixedVertexProcessing, pp);

            ReleaseCom(d3d);

            _device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

            var proj = Matrix.PerspectiveFovLH(
                (float)(Math.PI / 4),
                (float)pp.BackBufferWidth / pp.BackBufferHeight,
                0.1f / _setup.Scale, 1000.0f / _setup.Scale
                );

            _device.SetTransform(TransformState.Projection, proj);
            _displayMode = new SlimDX.Direct3D9.DisplayMode {
                Width       = pp.BackBufferWidth,
                Height      = pp.BackBufferHeight,
                RefreshRate = pp.FullScreenRefreshRateInHertz,
                Format      = pp.BackBufferFormat
            };
            _currentBackBuffer = 0;

            _sprite = new Sprite(_device);


            Window.Show();
            Window.Activate();
            _states      = new List <State>();
            CurrentState = null;

            ScriptManager = new ResourceManager <Script>();

            Input = new Input(Window);

            if (_setup.StateSetup != null)
            {
                _setup.StateSetup();
            }

            _loaded  = true;
            _running = true;
        }
Example #2
0
        public Engine(EngineSetup setup = null)
        {
            XmlConfigurator.Configure();

            _loaded = false;
            _setup = new EngineSetup();
            if (setup != null) {
                _setup = setup;
            }
            _gEngine = this;

            var d3d = new Direct3D();
            var enumeration = new DeviceEnumeration(d3d);
            if (enumeration.ShowDialog() != DialogResult.OK) {
                ReleaseCom(d3d);
                return;
            }

            Window = new FpsForm {
                Name = "WindowClass",
                Text = _setup.Name,
                FormBorderStyle = enumeration.Windowed ? FormBorderStyle.FixedSingle : FormBorderStyle.None,
                Size = new Size(800, 600)
            };

            var pp = new PresentParameters {
                BackBufferWidth = enumeration.SelectedDisplayMode.Width,
                BackBufferHeight = enumeration.SelectedDisplayMode.Height,
                BackBufferFormat = enumeration.SelectedDisplayMode.Format,
                BackBufferCount = _setup.TotalBackBuffers,
                SwapEffect = SwapEffect.Discard,
                DeviceWindowHandle = Window.Handle,
                Windowed =  enumeration.Windowed,
                EnableAutoDepthStencil =  true,
                AutoDepthStencilFormat = Format.D24S8,
                FullScreenRefreshRateInHertz = enumeration.SelectedDisplayMode.RefreshRate,
                PresentationInterval = enumeration.VSync ? PresentInterval.Default :  PresentInterval.Immediate,
                Multisample = MultisampleType.None,
                MultisampleQuality = 0,
                PresentFlags = PresentFlags.None

            };
            enumeration.Dispose();

            _device = new Device(d3d, 0, DeviceType.Hardware, Window.Handle, CreateFlags.MixedVertexProcessing, pp);

            ReleaseCom(d3d);

            _device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
            _device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

            var proj = Matrix.PerspectiveFovLH(
                (float) (Math.PI/4),
                (float)pp.BackBufferWidth/pp.BackBufferHeight,
                0.1f/_setup.Scale, 1000.0f/_setup.Scale
            );
            _device.SetTransform(TransformState.Projection, proj);
            _displayMode = new SlimDX.Direct3D9.DisplayMode {
                Width = pp.BackBufferWidth,
                Height = pp.BackBufferHeight,
                RefreshRate = pp.FullScreenRefreshRateInHertz,
                Format = pp.BackBufferFormat
            };
            _currentBackBuffer = 0;

            _sprite = new Sprite(_device);

            Window.Show();
            Window.Activate();
            _states = new List<State>();
            CurrentState = null;

            ScriptManager = new ResourceManager<Script>();

            Input = new Input(Window);

            if (_setup.StateSetup != null) {
                _setup.StateSetup();
            }

            _loaded = true;
            _running = true;
        }