Пример #1
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void Idle()
        {
            SlimDX.Direct3D9.Device device = Device;

            device.BeginScene();

            // reset the depth buffer to 1.0 and the render target to black
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
                         new Color4(0, 0, 0), 1.0f, 0);

            // prepare for drawing sprites. We need transparency and z-order
            Sprite.Begin(SpriteFlags.AlphaBlend
                         | SpriteFlags.SortDepthBackToFront);

            OnRender(new RenderEventArgs(this, Device));

            System.Diagnostics.Debug.Assert(device != null);

            // aaaannnd.... done!
            Sprite.End();

            // painting done ...
            device.EndScene();

            // ... so show the result on screen
            device.Present();

            OnIdleEvent(new EventArgs());
        }
Пример #2
0
        public bool RenderGauge()
        {
            try
            {
                if (device != null && !DX_reinit)
                {
                    Single brushAngle = (Int32)(m_BaseArcStart + (m_value - m_MinValue) * m_BaseArcSweep /
                                                (m_MaxValue - m_MinValue)) % 360;
                    Double needleAngle = brushAngle * Math.PI / 180;
                    verts1[0].X = (float)(Center.X + m_NeedleRadius / 4 * Math.Cos(needleAngle));
                    verts1[0].Y = (float)(Center.Y + m_NeedleRadius / 4 * Math.Sin(needleAngle));
                    verts1[1].X = (float)(Center.X + m_NeedleRadius * Math.Cos(needleAngle));
                    verts1[1].Y = (float)(Center.Y + m_NeedleRadius * Math.Sin(needleAngle));

                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black.ToArgb(), 0.0f, 0);
                    sprite.Begin(SpriteFlags.AlphaBlend);

                    if (BackgroundTexture != null)
                    {
                        sprite.Draw(BackgroundTexture, texture_size, (Color4)Color.White);
                    }

                    sprite.End();
                    //Begin the scene
                    device.BeginScene();
                    device.SetRenderState(RenderState.AlphaBlendEnable, true);
                    device.SetRenderState(RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha);
                    device.SetRenderState(RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.DestinationAlpha);
                    line.Draw(verts1, Color.Red);
                    device.EndScene();
                    device.Present();
                    return(true);
                }

                if (DX_reinit)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());

                if (DX_reinit)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #3
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;
                }
            }
        }
Пример #4
0
        public void Run()
        {
            if (_loaded)
            {
                Window.Show();

                ViewerSetup viewer = new ViewerSetup();

                _lastTime = Stopwatch.GetTimestamp();
                while (_running)
                {
                    Application.DoEvents();
                    if (!_deactive)
                    {
                        long currentTime = Stopwatch.GetTimestamp();

                        long elapsed = (currentTime - _lastTime) / Stopwatch.Frequency;
                        _lastTime = currentTime;

                        Input.Update();

                        if (Input.GetKeyPress(Key.Escape))
                        {
                            Quit();
                        }

                        if (CurrentState != null)
                        {
                            CurrentState.RequestViewer(out viewer);
                        }
                        _stateChanged = false;
                        if (CurrentState != null)
                        {
                            CurrentState.Update(elapsed);
                        }
                        if (_stateChanged)
                        {
                            continue;
                        }
                        try {
                            _device.Clear(viewer.ClearFlags, Color.White, 1.0f, 0);
                        } catch (Direct3D9Exception dex) {
                        }
                        if (_device.BeginScene().IsSuccess)
                        {
                            if (CurrentState != null)
                            {
                                CurrentState.Render();
                            }
                            _device.EndScene();
                            _device.Present();
                            if (++_currentBackBuffer == _setup.TotalBackBuffers + 1)
                            {
                                _currentBackBuffer = 0;
                            }
                        }
                    }
                }
                Release();
                Application.Exit();
            }
        }