예제 #1
0
파일: Game.cs 프로젝트: diqost/bullet
        public void ToggleFullScreen()
        {
            if (Context9 == null)
            {
                return;
            }

            togglingFullScreen = true;

            OnLostDevice();

            if (Context9.PresentParameters.Windowed)
            {
                windowedFormWindowState = Form.WindowState;
                windowedFormBorderStyle = Form.FormBorderStyle;

                Width  = Form.ClientSize.Width;
                Height = Form.ClientSize.Height;

                // Only normal window can be used in full screen.
                if (Form.WindowState != FormWindowState.Normal)
                {
                    Form.WindowState = FormWindowState.Normal;
                }

                Context9.PresentParameters.BackBufferWidth  = FullScreenWidth;
                Context9.PresentParameters.BackBufferHeight = FullScreenHeight;
                Form.FormBorderStyle = FormBorderStyle.None;

                Context9.PresentParameters.Windowed = false;
            }
            else
            {
                Context9.PresentParameters.BackBufferWidth  = Width;
                Context9.PresentParameters.BackBufferHeight = Height;
                Form.FormBorderStyle = windowedFormBorderStyle;
                Form.WindowState     = windowedFormWindowState;
                if (Form.WindowState == FormWindowState.Normal)
                {
                    Form.ClientSize = new System.Drawing.Size(Width, Height);
                }

                Context9.PresentParameters.Windowed = true;
            }

            Device.Reset(Context9.PresentParameters);
            OnResetDevice();

            togglingFullScreen = false;
        }
예제 #2
0
파일: Game.cs 프로젝트: diqost/bullet
        /// <summary>
        /// Renders the game.
        /// </summary>
        private void Render()
        {
            if (deviceLost)
            {
                // This should only become true if we're using D3D9, so we can assume the
                // D3D9 context is valid at this point.
                if (Device.TestCooperativeLevel() == SlimDX.Direct3D9.ResultCode.DeviceNotReset)
                {
                    Device.Reset(Context9.PresentParameters);
                    deviceLost = false;
                    OnResetDevice();
                }
                else
                {
                    Thread.Sleep(100);
                    return;
                }
            }

            frameAccumulator += FrameDelta;
            ++frameCount;
            if (frameAccumulator >= 1.0f)
            {
                FramesPerSecond = frameCount / frameAccumulator;

                frameAccumulator = 0.0f;
                frameCount       = 0;
            }

            try
            {
                OnRender();
            }
            catch (SlimDX.Direct3D9.Direct3D9Exception e)
            {
                if (e.ResultCode == SlimDX.Direct3D9.ResultCode.DeviceLost)
                {
                    OnLostDevice();
                    deviceLost = true;
                }
                else
                {
                    throw;
                }
            }
        }
예제 #3
0
        private void HandleResize(object sender, EventArgs e)
        {
            if (Form.WindowState == FormWindowState.Minimized)
            {
                return;
            }

            OnLostDevice();

            if (Context9 != null)
            {
                Context9.PresentParameters.BackBufferWidth  = Form.ClientSize.Width;
                Context9.PresentParameters.BackBufferHeight = Form.ClientSize.Height;

                Device.Reset(Context9.PresentParameters);
            }

            OnResetDevice();
        }
예제 #4
0
파일: Game.cs 프로젝트: diqost/bullet
        private void HandleResize(object sender, EventArgs e)
        {
            if (Form.WindowState == FormWindowState.Minimized)
            {
                return;
            }

            OnLostDevice();

            if (Context9 != null)
            {
                Context9.PresentParameters.BackBufferWidth  = Form.ClientSize.Width;
                Context9.PresentParameters.BackBufferHeight = Form.ClientSize.Height;

                Device.Reset(Context9.PresentParameters);
            }
            //else if( Context10 != null )
            //{
            //    Context10.SwapChain.ResizeBuffers( 1, WindowWidth, WindowHeight, Context10.SwapChain.Description.ModeDescription.Format, Context10.SwapChain.Description.Flags );
            //}

            OnResetDevice();
        }
예제 #5
0
        private void Render()
        {
            if (deviceLost)
            {
                // This should only become true if we're using D3D9, so we can assume the
                // D3D9 context is valid at this point.
                if (Device.TestCooperativeLevel() == global::SlimDX.Direct3D9.ResultCode.DeviceNotReset)
                {
                    Device.Reset(Context9.PresentParameters);
                    deviceLost = false;
                    OnResetDevice();
                }
                else
                {
                    Thread.Sleep(100);
                    return;
                }
            }

            try
            {
                Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);
                Device.BeginScene();

                foreach (CollisionObject colObj in Demo.World.CollisionObjectArray)
                {
                    if (colObj is SoftBody)
                    {
                        if (Demo.IsDebugDrawEnabled)
                        {
                            continue;
                        }

                        Device.Material = SoftBodyMaterial;
                        Device.SetTransform(TransformState.World, Matrix.Identity);
                        _meshFactory.RenderSoftBody(colObj as SoftBody);
                    }
                    else
                    {
                        if ("Ground".Equals(colObj.UserObject))
                        {
                            Device.Material = GroundMaterial;
                        }
                        else if (colObj.ActivationState == ActivationState.ActiveTag)
                        {
                            Device.Material = ActiveMaterial;
                        }
                        else
                        {
                            Device.Material = PassiveMaterial;
                        }
                        _meshFactory.Render(colObj);
                    }
                }

                if (Demo.IsDebugDrawEnabled)
                {
                    (Demo.World.DebugDrawer as PhysicsDebugDraw).DrawDebugWorld(Demo.World);
                }
                Info.OnRender(Demo.FramesPerSecond);

                Device.EndScene();
                Device.Present();
            }
            catch (global::SlimDX.Direct3D9.Direct3D9Exception e)
            {
                if (e.ResultCode == global::SlimDX.Direct3D9.ResultCode.DeviceLost)
                {
                    OnLostDevice();
                    deviceLost = true;
                }
                else
                {
                    throw;
                }
            }
        }