Exemple #1
0
        /// <summary>
        /// Function called when the application goes into an idle state.
        /// </summary>
        /// <returns><b>true</b> to continue executing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            if (_lightBrightDir)
            {
                _lightValue += 1.0f * GorgonTiming.Delta;
            }
            else
            {
                _lightValue -= 1.0f * GorgonTiming.Delta;
            }

            if (_torchFrameTime.Milliseconds > 250)
            {
                _torchSprite.TextureRegion =
                    _torchTexture.Texture.ToTexel(new DX.Rectangle(_torchSprite.TextureRegion.Left == 0 ? 56 : 0, 0, 55, _torchTexture.Height));
                _torchFrameTime.Reset();

                _lightValue = _torchSprite.TextureRegion.Left == 0 ? _lightMinMax.Maximum : _lightMinMax.Minimum;
            }

            if (_lightValue < _lightMinMax.Minimum)
            {
                _lightValue     = _lightMinMax.Minimum;
                _lightBrightDir = !_lightBrightDir;
            }

            if (_lightValue > _lightMinMax.Maximum)
            {
                _lightValue     = _lightMinMax.Maximum;
                _lightBrightDir = !_lightBrightDir;
            }

            _lightEffect.Lights[0].Color         = new GorgonColor((_lightValue * 253.0f) / 255.0f, (_lightValue * 248.0f) / 255.0f, (_lightValue * 230.0f) / 255.0f);
            _lightEffect.Lights[0].SpecularPower = (1.0f - (_lightValue / 1.2f)) * 15;

            _finalTarget.Clear(GorgonColor.BlackTransparent);
            _screen.RenderTargetView.Clear(GorgonColor.Black);

            // Render the lit sprite.
            _lightEffect.Render(DrawLitScene, _finalTarget);

            // Blit our final texture to the main screen.
            _graphics.SetRenderTarget(_screen.RenderTargetView);
            _renderer.Begin();
            _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _screen.Width, _screen.Height),
                                          GorgonColor.White,
                                          _finalTexture,
                                          new DX.RectangleF(0, 0, 1, 1));

            _renderer.DrawSprite(_torchSprite);

            _renderer.DrawString($"Specular Power: {_lightEffect.Lights[0].SpecularPower:0.0#####}\nLight [c #{GorgonColor.CornFlowerBlue.ToHex()}]Z[/c]: {_lightEffect.Lights[0].Position.Z:0.0}",
                                 new DX.Vector2(0, 64));
            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            _screen.Present(1);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Function to render the GUI (such as it is) to give feedback to the user.
        /// </summary>
        /// <param name="renderArea">The area in which we render our graphics.</param>
        /// <remarks>
        /// <para>
        /// The render area is our view into the rendered region on the window.  We wish to place our GUI into this area, so in order to do so, we'll need to adjust our drawing by the region.
        /// </para>
        /// </remarks>
        private static void RenderGui(DX.RectangleF renderArea)
        {
            _renderer.Begin();
            if (_showInstructions)
            {
                _textSprite.Text = string.Format("{0}\n\nShip 1: {1:0.0}x{2:0.0}\nShip 2: {3:0.0}x{4:0.0}\nBig Ship: {5:0.0}x{6:0.0}",
                                                 Resources.Instructions,
                                                 _ship.Position.X * 100,
                                                 _ship.Position.Y * 100,
                                                 _shipDeux.Position.X * 100,
                                                 _shipDeux.Position.Y * 100,
                                                 _bigShip.Position.X * 100,
                                                 _bigShip.Position.Y * 100);
                _renderer.DrawTextSprite(_textSprite);
            }

            float speed       = _ship.LayerController != null ? _ship.Speed : _shipDeux.Speed;
            float maxSpeed    = renderArea.Width * 0.12f * speed;
            var   speedRegion = new DX.RectangleF(renderArea.Left + 5, renderArea.Bottom - 30, renderArea.Width * 0.12f, 25);
            var   speedBar    = new DX.RectangleF(speedRegion.X, speedRegion.Y, maxSpeed, speedRegion.Height);

            _renderer.DrawFilledRectangle(speedRegion, new GorgonColor(GorgonColor.Black, 0.5f));
            _renderer.DrawFilledRectangle(speedBar, new GorgonColor(GorgonColor.GreenPure * 0.85f, 0.3f));
            _renderer.DrawString("Speed", new DX.Vector2(speedRegion.Left, speedRegion.Top - _helpFont.LineHeight + 5), _helpFont, GorgonColor.White);
            _renderer.DrawRectangle(speedRegion, new GorgonColor(GorgonColor.White, 0.3f));

            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);
        }
Exemple #3
0
        /// <summary>
        /// Function called when the application goes into an idle state.
        /// </summary>
        /// <returns><b>true</b> to continue executing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            _tileSize = new DX.Size2((int)(_screen.Width / _snowTile.ScaledSize.Width), (int)(_screen.Height / _snowTile.ScaledSize.Height));

            _screen.RenderTargetView.Clear(GorgonColor.White);
            _depthBuffer.Clear(1.0f, 0);

            // We have to pass in a state that allows depth writing and testing. Otherwise the depth buffer won't be used.
            _renderer.Begin(Gorgon2DBatchState.DepthEnabled);

            DrawBackground();

            // Note that the order that we draw here is not important since the depth buffer will sort on our behalf.
            // As mentioned in the description for the example, alpha blending doesn't work all that well with this
            // trick. You'll notice this when the guy walks behind the icicle as the icicle completely obscures the
            // guy even though the icicle has alpha translucency.
            DrawIcicle();

            DrawGuy();

            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            _controller.Update();

            AnimationTransition();

            _screen.Present(1);
            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Function to present the rendering to the main window.
        /// </summary>
        private static void Present()
        {
            if (_graphics.RenderTargets[0] != _screen.RenderTargetView)
            {
                _graphics.SetRenderTarget(_screen.RenderTargetView);
            }

            GorgonExample.DrawStatsAndLogo(_renderer);

            _screen.Present(1);
        }
Exemple #5
0
        /// <summary>
        /// Function for the main idle loop.
        /// </summary>
        /// <remarks>This is used as the main loop for the application.  All drawing and logic can go in here.</remarks>
        /// <returns><b>true</b> to keep running, <b>false</b> to exit.</returns>
        private static bool Idle()
        {
            if (!_paused)
            {
                // Update the simulation at our desired frame rate.
                if (GorgonTiming.Delta < MinSimulationFPS)
                {
                    _accumulator += GorgonTiming.Delta;
                }
                else
                {
                    _accumulator += MinSimulationFPS;
                }

                while (_accumulator >= MaxSimulationFPS)
                {
                    Transform(MaxSimulationFPS);
                    _accumulator -= MaxSimulationFPS;
                }
            }

            // Begin our rendering.
            _2D.Begin();
            DrawBackground();
            _2D.End();

            if (_blur.BlurRadius == 0)
            {
                _2D.Begin();
                DrawNoBlur();
                _2D.End();
            }
            else
            {
                DrawBlurred();
            }

            _2D.Begin();
            if (_showHelp)
            {
                _2D.DrawTextSprite(_helpTextSprite);
            }

            DrawOverlay();
            _2D.End();

            GorgonExample.DrawStatsAndLogo(_2D);

            _mainScreen.Present();

            _graphics.ResetDrawCallStatistics();

            return(true);
        }
Exemple #6
0
        /// <summary>
        /// Main application loop.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            ProcessKeys();

            _swapChain.RenderTargetView.Clear(Color.CornflowerBlue);
            _depthBuffer.Clear(1.0f, 0);

            _cloudRotation += 2.0f * GorgonTiming.Delta;
            _objRotation   += 50.0f * GorgonTiming.Delta;

            if (_cloudRotation > 359.9f)
            {
                _cloudRotation -= 359.9f;
            }

            if (_objRotation > 359.9f)
            {
                _objRotation -= 359.9f;
            }

            _triangle.Material.TextureOffset = new DX.Vector2(0, _triangle.Material.TextureOffset.Y - (0.125f * GorgonTiming.Delta));

            if (_triangle.Material.TextureOffset.Y < 0.0f)
            {
                _triangle.Material.TextureOffset = new DX.Vector2(0, 1.0f + _triangle.Material.TextureOffset.Y);
            }

            _plane.Material.TextureOffset = _triangle.Material.TextureOffset;

            _icoSphere.Rotation = new DX.Vector3(0, _icoSphere.Rotation.Y + (4.0f * GorgonTiming.Delta), 0);
            _cube.Rotation      = new DX.Vector3(_objRotation, _objRotation, _objRotation);
            _sphere.Position    = new DX.Vector3(-2.0f, (_objRotation.ToRadians().Sin().Abs() * 2.0f) - 1.10f, 0.75f);
            _sphere.Rotation    = new DX.Vector3(_objRotation, _objRotation, 0);
            _clouds.Rotation    = new DX.Vector3(0, _cloudRotation, 0);

            _renderer.Render();

            _2DRenderer.Begin();
            _textSprite.Text = $@"FPS: {GorgonTiming.FPS:0.0}, Delta: {(GorgonTiming.Delta * 1000):0.000} msec. " +
                               $@"Tris: {
		                               ((_triangle.TriangleCount) + (_plane.TriangleCount) + (_cube.TriangleCount) + (_sphere.TriangleCount) + (_icoSphere.TriangleCount) +
		                                (_clouds.TriangleCount))
		                           :0} "         +
                               $@"CamRot: {_cameraRotation} Mouse: {_mouse?.Position.X:0}x{_mouse?.Position.Y:0} Sensitivity: {_sensitivity:0.0##}";
            _2DRenderer.DrawTextSprite(_textSprite);
            _2DRenderer.End();

            GorgonExample.DrawStatsAndLogo(_2DRenderer);

            _swapChain.Present();

            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Function to do perform processing for the application during idle time.
        /// </summary>
        /// <returns><b>true</b> to continue execution, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            GorgonSprite shadowSprite = _fgSprite == _sprite2 ? _shadowSprites[1] : _shadowSprites[0];

            // Draw our background that includes our background texture, and the sprite that's currently in the background (along with its shadow).
            // Blurring may or may not be applied depending on whether the user has applied it with the mouse wheel.
            DrawBlurredBackground();

            // Reset scales for our sprites. Foreground sprites will be larger than our background ones.
            shadowSprite.Scale = _fgSprite.Scale = DX.Vector2.One;

            // Ensure we're on the "screen" when we render.
            _graphics.SetRenderTarget(_screen.RenderTargetView);

            _renderer.Begin();

            // Draw our blurred (or not) background.
            _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _screen.Width, _screen.Height),
                                          GorgonColor.White,
                                          _blurTexture,
                                          new DX.RectangleF(0, 0, 1, 1));

            // Draw an ellipse to indicate our light source.
            var lightPosition = new DX.RectangleF((_screen.Width / 2.0f) - 10, (_screen.Height / 2.0f) - 10, 20, 20);

            _renderer.DrawFilledEllipse(lightPosition, GorgonColor.White, 0.5f);

            // Draw the sprite and its corresponding shadow.
            // We'll adjust the shadow position to be altered by our distance from the light source, and the quadrant of the screen that we're in.
            shadowSprite.Position = _fgSprite.Position + (new DX.Vector2(_fgSprite.Position.X - (_screen.Width / 2.0f), _fgSprite.Position.Y - (_screen.Height / 2.0f)) * 0.125f);

            _renderer.DrawSprite(shadowSprite);
            _renderer.DrawSprite(_fgSprite);

            if (_showHelp)
            {
                _renderer.DrawString(HelpText, new DX.Vector2(2, 2), _helpFont, GorgonColor.White);
            }

            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            _screen.Present(1);

            return(true);
        }
Exemple #8
0
        /// <summary>
        /// Function to perform operations while the CPU is idle.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            // Set the initial background color, we won't be clearing again...
            _screen.RenderTargetView.Clear(GorgonColor.CornFlowerBlue);

            if (!_mp3Player.IsPlaying)
            {
                PlayAudio();
            }

            if (_animController.CurrentAnimation == null)
            {
                _animController.Play(_animatedSprite, _animation);
            }

            _graphics.SetRenderTarget(_target);
            _renderer.Begin(_targetBatchState);
            _renderer.DrawSprite(_animatedSprite);
            _renderer.End();

            _graphics.SetRenderTarget(_screen.RenderTargetView);
            _renderer.Begin();
            _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _screen.Width, _screen.Height),
                                          GorgonColor.White,
                                          _targetView,
                                          new DX.RectangleF(0, 0, 1, 1));
            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            // We need to call this once per frame so the animation will transition properly.
            _animController.Update();

            _screen.Present(1);

            return(true);
        }
Exemple #9
0
        /// <summary>
        /// Function to process the example functionality during idle time.
        /// </summary>
        /// <returns><b>true</b> to continue, <b>false</b> to stop.</returns>
        private bool Idle()
        {
            _leftPanel.RenderTargetView.Clear(GroupControl1.BackColor);
            _rightPanel.RenderTargetView.Clear(GroupControl2.BackColor);

            _graphics.SetRenderTarget(_leftPanel.RenderTargetView);

            _renderer.Begin();
            _torusLeft.Scale    = _scale;
            _torusLeft.Position = new DX.Vector2(_leftPanel.Width / 2.0f, _leftPanel.Height / 2.0f);
            _renderer.DrawSprite(_torusLeft);
            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            _graphics.SetRenderTarget(_rightPanel.RenderTargetView);

            _renderer.Begin();
            _torusLeft.Scale = DX.Vector2.One;

            _torusRight.Color    = GorgonColor.RedPure;
            _torusRight.Position = new DX.Vector2((_rightPanel.Width / 2.0f) - 64, (_rightPanel.Height / 2.0f) - 64);
            _renderer.DrawSprite(_torusRight);

            _torusRight.Color    = GorgonColor.GreenPure;
            _torusRight.Position = new DX.Vector2((_rightPanel.Width / 2.0f) + 64, (_rightPanel.Height / 2.0f) - 64);
            _renderer.DrawSprite(_torusRight);

            _torusRight.Color    = GorgonColor.BluePure;
            _torusRight.Position = new DX.Vector2((_rightPanel.Width / 2.0f) - 64, (_rightPanel.Height / 2.0f) + 64);
            _renderer.DrawSprite(_torusRight);

            _torusRight.Color    = GorgonColor.White;
            _torusRight.Position = new DX.Vector2((_rightPanel.Width / 2.0f) + 64, (_rightPanel.Height / 2.0f) + 64);
            _renderer.DrawSprite(_torusRight);

            _renderer.DrawString("\u2190Drag me!", new DX.Vector2(0, _rightPanel.Height / 4.0f), _appFont, GorgonColor.White);

            if (_controllerRight.State != AnimationState.Playing)
            {
                _renderer.DrawString("Speed: Stopped", new DX.Vector2(0, 64), _appFont, GorgonColor.White);
            }
            else
            {
                _renderer.DrawString($"Speed: {TrackSpeed.Value / 5.0f:0.0#}", new DX.Vector2(0, 64), _appFont, GorgonColor.White);
            }

            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            _leftPanel.Present(1);
            _rightPanel.Present(1);

            _torusAnim.Speed = 1.0f;
            _controllerLeft.Update();

            if (_controllerRight.State != AnimationState.Playing)
            {
                _controllerRight.Resume();
                _controllerRight.Time = (TrackSpeed.Value / 10.0f) * _torusAnim.Length;
                _controllerRight.Pause();
            }
            else
            {
                _torusAnim.Speed = TrackSpeed.Value / 5.0f;
                _controllerRight.Update();
            }

            return(true);
        }
Exemple #10
0
        /// <summary>
        /// Function to handle idle time processing.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns>
        private bool Idle()
        {
            int width  = ClientSize.Width;
            int height = ClientSize.Height;

            _screen.RenderTargetView.Clear(Color.FromArgb(250, 245, 220));

            // Reset the text position.
            if (_poetry.Position.Y < -_poetry.Size.Height)
            {
                _textPosition = new DX.Vector2(0, height + _textFont.LineHeight);
            }

            // Scroll up.
            _textPosition.Y -= (25.0f * GorgonTiming.Delta);

            // Alter blur value.
            _blurAmount += _blurDelta * GorgonTiming.Delta;

            if (_blurAmount < 0.0f)
            {
                _blurAmount = 0.0f;
                _blurDelta  = -_blurDelta;
            }

            if (_blurAmount > 64)
            {
                _blurAmount = 64;
                _blurDelta  = -_blurDelta;
            }

            int index = 0;

            ResetBlur();

            if (_blurAmount > 0)
            {
                // Blur for the count we specify.
                int blurCount = (int)_blurAmount;
                for (int i = 0; i < blurCount; ++i)
                {
                    int imageIndex  = index = i % 2;
                    int targetIndex = index == 0 ? 1 : 0;
                    _blurEffect.Render((_, __, ___) => _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _blurredTarget[0].Width, _blurredTarget[0].Height),
                                                                                     GorgonColor.White,
                                                                                     _blurredImage[imageIndex],
                                                                                     new DX.RectangleF(0, 0, 1, 1)),
                                       _blurredTarget[targetIndex]);
                }
            }

            // Switch back to our screen for rendering.
            _graphics.SetRenderTarget(_screen.RenderTargetView);


            // Draw the base.
            _renderer.Begin();

            // Draw text.
            _poetry.Position = _textPosition;
            _renderer.DrawTextSprite(_poetry);

            _sprites[0].Position = new DX.Vector2(width / 4, height / 4);

            // Draw motherships.
            _sprites[1].Position = new DX.Vector2(width - (width / 4), height / 4);

            _renderer.DrawSprite(_sprites[0]);
            _renderer.DrawSprite(_sprites[1]);

            // Draw our blurred image (we could have used a sprite here as well, but this works just as well).
            _renderer.DrawFilledRectangle(new DX.RectangleF((width / 2) - (_blurredImage[0].Width / 2.0f),
                                                            (height / 2) - (_blurredImage[0].Height / 2.0f),
                                                            _blurredImage[0].Width,
                                                            _blurredImage[0].Height),
                                          GorgonColor.White,
                                          _blurredImage[index],
                                          new DX.RectangleF(0, 0, 1, 1));

            // Draw help text.
            if (_showHelp)
            {
                _renderer.DrawTextSprite(_helpText);
            }

            // Show our rendering statistics.
            if (_showStats)
            {
                var rectPosition = new DX.RectangleF(0, 0, width, (_helpFont.FontHeight * 2.0f) + 2.0f);
                _renderer.DrawFilledRectangle(rectPosition, Color.FromArgb(192, Color.Black));
                _renderer.DrawLine(rectPosition.X, rectPosition.Bottom, rectPosition.Width, rectPosition.Bottom, Color.White);
                _renderer.DrawString($"FPS: {GorgonTiming.FPS:0.0}\nFrame Delta: {(GorgonTiming.Delta * 1000):0.0##} msec.",
                                     DX.Vector2.Zero,
                                     _helpFont,
                                     GorgonColor.White);
            }

            _renderer.End();

            GorgonExample.ShowStatistics = _showStats;
            GorgonExample.DrawStatsAndLogo(_renderer);

            _screen.Present(1);
            return(true);
        }
Exemple #11
0
        /// <summary>
        /// Function called when the application goes into an idle state.
        /// </summary>
        /// <returns><b>true</b> to continue executing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            _angle1 += 45.0f * GorgonTiming.Delta;
            _angle2 -= 30.0f * GorgonTiming.Delta;

            if (_angle1 > 360.0f)
            {
                _angle1 -= 360.0f;
            }

            if (_angle2 < 0.0f)
            {
                _angle2 = 360.0f + _angle2;
            }

            _screen.RenderTargetView.Clear(new GorgonColor(0, 0, 0.2f));

            // Draw standard sprites.
            _renderer.Begin();

            _renderer.DrawString("Polygonal Sprite",
                                 new DX.Vector2((_screen.Width / 4.0f) - (_polySprite.Size.Width * 0.5f),
                                                (_screen.Height / 4.0f) - (_polySprite.Size.Height * 0.5f) - _renderer.DefaultFont.LineHeight));

            _renderer.DrawString("Polygonal Sprite (Wireframe)",
                                 new DX.Vector2(_screen.Width - (_screen.Width / 4.0f) - (_polySprite.Size.Width * 0.5f),
                                                (_screen.Height / 4.0f) - (_polySprite.Size.Height * 0.5f) - _renderer.DefaultFont.LineHeight));

            _renderer.DrawString("Rectangular Sprite",
                                 new DX.Vector2((_screen.Width / 4.0f) - (_polySprite.Size.Width * 0.5f),
                                                _screen.Height - (_screen.Height / 4.0f) - (_polySprite.Size.Height * 0.5f) - _renderer.DefaultFont.LineHeight));

            _renderer.DrawString("Rectangular Sprite (Wireframe)",
                                 new DX.Vector2(_screen.Width - (_screen.Width / 4.0f) - (_polySprite.Size.Width * 0.5f),
                                                _screen.Height - (_screen.Height / 4.0f) - (_polySprite.Size.Height * 0.5f) - _renderer.DefaultFont.LineHeight));

            _normalSprite.Texture  = _texture;
            _normalSprite.Angle    = _angle1;
            _normalSprite.Position = new DX.Vector2(_screen.Width / 4.0f, _screen.Height - (_screen.Height / 4.0f));

            _polySprite.Texture  = _texture;
            _polySprite.Angle    = _angle2;
            _polySprite.Position = new DX.Vector2(_screen.Width / 4.0f, (_screen.Height / 4.0f));

            _renderer.DrawSprite(_normalSprite);
            _renderer.DrawPolygonSprite(_polySprite);

            _renderer.End();

            // Draw wireframe versions.
            _renderer.Begin(Gorgon2DBatchState.WireFrameNoCulling);

            _normalSprite.Texture  = null;
            _normalSprite.Angle    = _angle2;
            _normalSprite.Position = new DX.Vector2(_screen.Width - (_screen.Width / 4.0f), _screen.Height - (_screen.Height / 4.0f));

            _polySprite.Texture  = null;
            _polySprite.Angle    = _angle1;
            _polySprite.Position = new DX.Vector2(_screen.Width - (_screen.Width / 4.0f), (_screen.Height / 4.0f));

            _renderer.DrawSprite(_normalSprite);
            _renderer.DrawPolygonSprite(_polySprite);

            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            _screen.Present(1);

            return(true);
        }
Exemple #12
0
        /// <summary>
        /// Function called during idle time the application.
        /// </summary>
        /// <returns><b>true</b> to continue executing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            GorgonFont currentFont = _font[_fontIndex];

            if (_startTime < 0)
            {
                _startTime = GorgonTiming.SecondsSinceStart;
            }

            _screen.RenderTargetView.Clear(_glowIndex != _fontIndex ? GorgonColor.CornFlowerBlue : new GorgonColor(0, 0, 0.2f));

            DX.Size2F textSize = currentFont.MeasureText(Resources.Lorem_Ipsum, false);
            var       position = new DX.Vector2((int)((_screen.Width / 2.0f) - (textSize.Width / 2.0f)).Max(4.0f), (int)((_screen.Height / 2.0f) - (textSize.Height / 2.0f)).Max(100));

            _text.Font     = currentFont;
            _text.Position = position;

            // If we have glow on, then draw the glow outline in a separate pass.
            if (_glowIndex == _fontIndex)
            {
                _text.OutlineTint = new GorgonColor(1, 1, 1, _glowAlpha);
                _text.DrawMode    = TextDrawMode.OutlineOnly;
                _renderer.Begin(Gorgon2DBatchState.AdditiveBlend);
                _renderer.DrawTextSprite(_text);
                _renderer.End();
            }

            _text.OutlineTint = GorgonColor.White;
            _text.Color       = _glowIndex != _fontIndex ? GorgonColor.White : GorgonColor.Black;
            _text.DrawMode    = ((_glowIndex == _fontIndex) || (!currentFont.HasOutline)) ? TextDrawMode.GlyphsOnly : TextDrawMode.OutlinedGlyphs;

            // Draw the font identification.
            _renderer.Begin();
            _renderer.DrawString($"Now displaying [c #FFFFE03F]'{currentFont.Name}'[/c]...", new DX.Vector2(4.0f, 64.0f));
            _renderer.DrawTextSprite(_text);
            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            // Animate our glow alpha.
            _glowAlpha += _glowVelocity * GorgonTiming.Delta;

            if (_glowAlpha > 1.0f)
            {
                _glowAlpha    = 1.0f;
                _glowVelocity = -0.5f;
            }
            else if (_glowAlpha < 0.25f)
            {
                _glowAlpha    = 0.25f;
                _glowVelocity = 0.5f;
            }

            // Animate the line height so we can drop the lines and make them bounce... just because we can.
            float normalSin = (_bounceAngle.ToRadians().Sin() + 1.0f) / 2.0f;
            float scaledSin = normalSin * (1.0f - _max);

            _text.LineSpace = scaledSin + _max;

            _bounceAngle += _angleSpeed * GorgonTiming.Delta;

            if (_bounceAngle > 90.0f)
            {
                _bounceAngle = 90.0f;
                if (_max.EqualsEpsilon(0))
                {
                    _max = 0.5f;
                }
                else
                {
                    _max += 0.125f;
                }

                if (_max >= 1.0f)
                {
                    _max = 1.0f;
                }
                _angleSpeed = -_angleSpeed * (_max + 1.0f);
            }

            if (_bounceAngle < -90.0f)
            {
                _angleSpeed  = -_angleSpeed;
                _bounceAngle = -90.0f;
            }

            int timeDiff = (int)(GorgonTiming.SecondsSinceStart - _startTime).FastCeiling();

            // Switch to a new font every 4 seconds.
            if (timeDiff > 4)
            {
                _startTime = GorgonTiming.SecondsSinceStart;
                ++_fontIndex;
                _text.LineSpace = -0.015f;

                // Reset glow animation.
                if (_fontIndex == _glowIndex)
                {
                    _glowAlpha    = 1.0f;
                    _glowVelocity = -0.5f;
                }

                // Reset bounce.
                _bounceAngle = -90.0f;
                _max         = 0.0f;
                _angleSpeed  = 360.0f;
            }


            if (_fontIndex >= _font.Count)
            {
                _fontIndex = 0;
            }

            _screen.Present(1);

            return(true);
        }
Exemple #13
0
        /// <summary>
        /// Function to perform operations while the CPU is idle.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            _postTarget1.Clear(GorgonColor.Black);

            DX.Vector2 textureSize = _background.Texture.ToTexel(new DX.Vector2(_postTarget1.Width, _postTarget1.Height));

            // Blit the background texture.
            _graphics.SetRenderTarget(_postTarget1);
            _renderer.Begin();
            _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _postTarget1.Width, _postTarget1.Height),
                                          GorgonColor.White,
                                          _background,
                                          new DX.RectangleF(_backgroundOffset.X, _backgroundOffset.Y, textureSize.X, textureSize.Y));
            _shipSprite.Color = new GorgonColor(GorgonColor.White, _cloakController.Opacity);
            _renderer.DrawSprite(_shipSprite);
            _renderer.End();

            // No sense in rendering the effect if it's not present.
            float strength = _cloakController.CloakAmount;

            if (strength > 0.0f)
            {
                // Don't bother recording the current state, we're going to be updating it shortly, so it'd be redundant.
                _displacement.Strength = strength;
                _displacement.Render((passIndex, _, __) => DrawDisplacement(passIndex),
                                     _postTarget2);
            }
            else
            {
                // Send the undisplaced image to the 2nd post process target.
                _graphics.SetRenderTarget(_postTarget2);

                _renderer.Begin();
                _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _postTarget1.Width, _postTarget1.Height),
                                              GorgonColor.White,
                                              _postView1,
                                              new DX.RectangleF(0, 0, 1, 1));
                _renderer.End();
            }

            // Smooth our results.
            int blurRadiusUpdate = GorgonRandom.RandomInt32(0, 1000000);

            if (blurRadiusUpdate > 997000)
            {
                _gaussBlur.BlurRadius = (_gaussBlur.BlurRadius + 1).Min(_gaussBlur.MaximumBlurRadius / 2);
            }
            else if (blurRadiusUpdate < 3000)
            {
                _gaussBlur.BlurRadius = (_gaussBlur.BlurRadius - 1).Max(1);
            }

            // If we didn't blur (radius = 0), then just use the original view.
            if (_gaussBlur.BlurRadius > 0)
            {
                _gaussBlur.Render((_, __, outputSize) =>
                {
                    _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, outputSize.Width, outputSize.Height),
                                                  GorgonColor.White,
                                                  _postView2,
                                                  new DX.RectangleF(0, 0, 1, 1));
                },
                                  _postTarget2);
            }

            // Render as an old film effect.
            _oldFilm.Time = GorgonTiming.SecondsSinceStart * 2;
            DX.Vector2 offset = DX.Vector2.Zero;
            if (GorgonRandom.RandomInt32(0, 100) > 95)
            {
                offset = new DX.Vector2(GorgonRandom.RandomSingle(-2.0f, 2.0f), GorgonRandom.RandomSingle(-1.5f, 1.5f));
            }

            _oldFilm.Render((_, __, size) =>
                            _renderer.DrawFilledRectangle(new DX.RectangleF(offset.X, offset.Y, size.Width, size.Height),
                                                          GorgonColor.White,
                                                          _postView2,
                                                          new DX.RectangleF(0, 0, 1, 1)),
                            _postTarget1);

            // Send to our screen.
            _screen.RenderTargetView.Clear(GorgonColor.Black);
            _graphics.SetRenderTarget(_screen.RenderTargetView);

            _renderer.Begin(Gorgon2DBatchState.NoBlend);
            if (GorgonRandom.RandomInt32(0, 100) < 2)
            {
                _finalBrightness = GorgonRandom.RandomSingle(0.65f, 1.0f);
            }

            _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _finalView.Width, _finalView.Height),
                                          new GorgonColor(_finalBrightness, _finalBrightness, _finalBrightness, 1.0f),
                                          _postView1,
                                          new DX.RectangleF(0, 0, 1, 1));
            _renderer.End();

            _renderer.Begin();
            if (_showHelp)
            {
                _renderer.DrawString(HelpText, new DX.Vector2(0, 64), color: new GorgonColor(1.0f, 1.0f, 0));
            }
            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            // Flip our back buffers over.
            _screen.Present(1);

            _cloakController.Update();

            return(true);
        }
Exemple #14
0
        /// <summary>
        /// Function to draw the pretty picture.
        /// </summary>
        private void DrawAPrettyPicture()
        {
            // Paint color.
            Color paintColor;

            // Clear the back buffer.
            _screen.RenderTargetView.Clear(Color.FromArgb(0, 0, 64));

            // First, we need to inform the renderer that we're about draw some stuff.
            _renderer.Begin();

            // Draw some points as stars.
            for (int x = 0; x < 1000; x++)
            {
                // Color.
                int colorSwitch = GorgonRandom.RandomInt32(160) + 95;   // Color component for the points.

                // Get the star color.
                paintColor = Color.FromArgb(colorSwitch, colorSwitch, colorSwitch);

                _renderer.DrawFilledRectangle(new DX.RectangleF(GorgonRandom.RandomSingle(_screen.Width), GorgonRandom.RandomSingle(_screen.Height), 1, 1), paintColor);
            }

            // Draw lines.
            for (int x = 0; x < 360; x++)
            {
                float cos = (x + (x / 2.0f)).FastCos();     // Cosine.
                float sin = (x + (x / 3.0f)).FastSin();     // Sin.

                // Set up a random color.
                paintColor = Color.FromArgb((byte)GorgonRandom.RandomInt32(128, 255), GorgonRandom.RandomInt32(64, 255), GorgonRandom.RandomInt32(64, 255), 0);
                var startPosition = new DX.Vector2(sin + _halfSize.Width, cos + _halfSize.Height);
                var endPosition   = new DX.Vector2((cos * (GorgonRandom.RandomSingle(_halfSize.Width * 0.82f))) + startPosition.X, (sin * (GorgonRandom.RandomSingle(_halfSize.Height * 0.82f))) + startPosition.Y);
                _renderer.DrawLine(startPosition.X, startPosition.Y, endPosition.X, endPosition.Y, paintColor);
                //Gorgon.Screen.Line(sin + _halfWidth, cos + _halfHeight, cos * (RandomValue * _halfWidth), sin * (RandomValue * _halfHeight), paintColor);
            }

            // Draw a filled circle.
            float size = (_halfSize.Width / 2.0f) + (GorgonRandom.RandomInt32(10) - 8);
            float half = size / 2.0f;

            _renderer.DrawFilledEllipse(new DX.RectangleF(_halfSize.Width - half, _halfSize.Height - half, size, size), Color.Yellow);

            // Draw some circles in the filled circle (sunspots).
            for (int x = 0; x < 25; x++)
            {
                float radius       = GorgonRandom.RandomSingle(5.0f);
                var   spotPosition = new DX.Vector2((GorgonRandom.RandomSingle((_halfSize.Height / 2.0f)) + _halfSize.Width - (_halfSize.Height / 4.0f)),
                                                    (GorgonRandom.RandomSingle((_halfSize.Height / 2.0f)) + _halfSize.Height - (_halfSize.Height / 4.0f)));
                _renderer.DrawEllipse(new DX.RectangleF(spotPosition.X - (radius * 0.5f),
                                                        spotPosition.Y - (radius * 0.5f),
                                                        radius,
                                                        radius),
                                      Color.Black);
            }

            // Draw some black bars.
            _renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, _screen.Width, _screen.Height / 6.0f), Color.Black);
            _renderer.DrawFilledRectangle(new DX.RectangleF(0, _screen.Height - (_screen.Height / 6.0f), _screen.Width, _screen.Height / 6.0f), Color.Black);

            // Tell the renderer that we're done drawing so we can actually render the shapes.
            _renderer.End();

            GorgonExample.DrawStatsAndLogo(_renderer);

            // Always call this when done or you won't see anything.
            _screen.Present(1);
        }