Пример #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            _selectedDisplayMode             = new SlimDX.Direct3D9.DisplayMode();
            _selectedDisplayMode.Width       = LowWord(cbResolution.SelectedItem != null ? ((KeyValuePair <long, string>)cbResolution.SelectedItem).Key : 0);
            _selectedDisplayMode.Height      = HighWord(cbResolution.SelectedItem != null ?((KeyValuePair <long, string>)cbResolution.SelectedItem).Key : 0);
            _selectedDisplayMode.RefreshRate = (int)(cbRefresh.SelectedItem != null ? ((KeyValuePair <long, string>)cbRefresh.SelectedItem).Key : 0);
            _selectedDisplayMode.Format      = cbColorFormat.SelectedItem != null ? ((KeyValuePair <Format, string>)cbColorFormat.SelectedItem).Key : Format.Unknown;
            _windowed = rbWindowed.Checked;
            _vsync    = chkVSync.Checked;

            _settingsScript.AddVariable("windowed", VariableType.Bool, _windowed);
            _settingsScript.AddVariable("vsync", VariableType.Bool, _vsync);
            _settingsScript.AddVariable("bpp", VariableType.Number, (long)_selectedDisplayMode.Format);
            _settingsScript.AddVariable("resolution", VariableType.Number, MakeLong(_selectedDisplayMode.Width, _selectedDisplayMode.Width));
            _settingsScript.AddVariable("refresh", VariableType.Number, (long)_selectedDisplayMode.RefreshRate);

            _settingsScript.SaveScript();
        }
Пример #2
0
 public ViewportDX(ViewportParams p)
 {
     Params = p;
     D3D    = new DX.Direct3D();
     //Получаем текущий режим экрана
     DX.DisplayMode mode = D3D.GetAdapterDisplayMode(0);
     //Инициализируем параметры
     d3dpp.AutoDepthStencilFormat = DX.Format.D16;
     d3dpp.BackBufferCount        = 1;
     d3dpp.BackBufferFormat       = mode.Format;
     d3dpp.BackBufferHeight       = p.WindowHeight;
     d3dpp.BackBufferWidth        = p.WindowWidth;
     //Куда рисовать
     d3dpp.DeviceWindowHandle = p.ControlHandle;
     //Контроль вертикальной развертки
     if (p.VerticalSync)
     {
         d3dpp.PresentationInterval = DX.PresentInterval.Default;
     }
     else
     {
         d3dpp.PresentationInterval = DX.PresentInterval.Immediate;
     }
     d3dpp.SwapEffect             = DX.SwapEffect.Discard;
     d3dpp.Windowed               = !p.FullScreen;
     d3dpp.EnableAutoDepthStencil = true;
     if (!p.FullScreen && p.VerticalSync)
     {
         d3dpp.SwapEffect = DX.SwapEffect.Copy;
     }
     //Создаем девайс
     Device = new DX.Device(D3D, 0, DX.DeviceType.Hardware, p.ControlHandle, DX.CreateFlags.HardwareVertexProcessing, d3dpp);
     if (Device == null)
     {
         throw new NullReferenceException("Не удалось инициализировать устройство!");
     }
 }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
0
		/// <summary>
		///		Accepts a existing Direct3D.DisplayMode object.
		/// </summary>
		public VideoMode( D3D.DisplayMode videoMode )
		{
			modeNum = ++modeCount;
			displayMode = videoMode;
		}
Пример #6
0
		/// <summary>
		///		Default constructor.
		/// </summary>
		public VideoMode()
		{
			modeNum = ++modeCount;
			displayMode = new D3D.DisplayMode();
		}
Пример #7
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            _selectedDisplayMode = new SlimDX.Direct3D9.DisplayMode();
            _selectedDisplayMode.Width = LowWord(cbResolution.SelectedItem!= null ? ((KeyValuePair<long, string>) cbResolution.SelectedItem).Key : 0);
            _selectedDisplayMode.Height = HighWord(cbResolution.SelectedItem!= null ?((KeyValuePair<long, string>) cbResolution.SelectedItem).Key : 0);
            _selectedDisplayMode.RefreshRate = (int)(cbRefresh.SelectedItem != null ? ((KeyValuePair<long, string>) cbRefresh.SelectedItem).Key : 0);
            _selectedDisplayMode.Format = cbColorFormat.SelectedItem!=null ? ((KeyValuePair<Format, string>) cbColorFormat.SelectedItem).Key : Format.Unknown;
            _windowed = rbWindowed.Checked;
            _vsync = chkVSync.Checked;

            _settingsScript.AddVariable("windowed", VariableType.Bool, _windowed);
            _settingsScript.AddVariable("vsync", VariableType.Bool, _vsync);
            _settingsScript.AddVariable("bpp", VariableType.Number, (long)_selectedDisplayMode.Format);
            _settingsScript.AddVariable("resolution", VariableType.Number, MakeLong(_selectedDisplayMode.Width, _selectedDisplayMode.Width));
            _settingsScript.AddVariable("refresh", VariableType.Number, (long)_selectedDisplayMode.RefreshRate);

            _settingsScript.SaveScript();
        }