Ejemplo n.º 1
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                // Now begin running the application idle loop.
                GorgonApplication.Run(Initialize(), Idle);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                // Always clean up when you're done.
                // Since Gorgon uses Direct 3D 11.x, which allocate objects that use native memory and COM objects, we must be careful to dispose of any objects that implement
                // IDisposable. Failure to do so can lead to warnings from the Direct 3D runtime when running in DEBUG mode.
                GorgonExample.UnloadResources();

                _constantBuffer?.Dispose();
                _vertexBuffer.VertexBuffer?.Dispose();
                _inputLayout?.Dispose();
                _vertexShader?.Dispose();
                _pixelShader?.Dispose();
                _swap?.Dispose();
                _graphics?.Dispose();
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Function to load the images for use with the example.
        /// </summary>
        /// <param name="codec">The codec for the images.</param>
        /// <returns><b>true</b> if files were loaded successfully, <b>false</b> if not.</returns>
        private static bool LoadImageFiles(IGorgonImageCodec codec)
        {
            DirectoryInfo dirInfo = GorgonExample.GetResourcePath(@"\Textures\PostProcess");

            FileInfo[] files = dirInfo.GetFiles("*.dds", SearchOption.TopDirectoryOnly);

            if (files.Length == 0)
            {
                GorgonDialogs.ErrorBox(null, $"No DDS images found in {dirInfo.FullName}.");
                GorgonApplication.Quit();
                return(false);
            }

            _images = new GorgonTexture2DView[files.Length];

            // Load all the DDS files from the resource area.
            for (int i = 0; i < files.Length; ++i)
            {
                _images[i] = GorgonTexture2DView.FromFile(_graphics,
                                                          files[i].FullName,
                                                          codec,
                                                          new GorgonTexture2DLoadOptions
                {
                    Binding = TextureBinding.ShaderResource,
                    Usage   = ResourceUsage.Immutable,
                    Name    = Path.GetFileNameWithoutExtension(files[i].Name)
                });
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                GorgonExample.PlugInLocationDirectory = new DirectoryInfo(Settings.Default.PlugInLocation);
                GorgonExample.ResourceBaseDirectory   = new DirectoryInfo(Settings.Default.ResourceLocation);

                // Create our virtual file system.
                _fileSystem = new GorgonFileSystem(Program.Log);
                _writer     = new GorgonFileSystemWriter(_fileSystem, Program.WriteDirectory.FullName);

                LoadText();

                labelFileSystem.Text    = $"{GorgonExample.GetResourcePath(@"FolderSystem\").FullName.Ellipses(100, true)} mounted as '/'.";
                labelWriteLocation.Text = $"{Program.WriteDirectory.FullName.Ellipses(100, true)} mounted as '/'";
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
                GorgonApplication.Quit();
            }
            finally
            {
                CommandEnable(!string.Equals(_originalText, _changedText, StringComparison.CurrentCulture));
                UpdateInfo();
            }
        }
Ejemplo n.º 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                GorgonApplication.Run(Initialize(), Idle);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();

                _helpFont?.Dispose();
                _shadowTexture?.Dispose();
                _gaussBlur?.Dispose();
                _spriteTexture?.Dispose();
                _backgroundTexture?.Dispose();
                _renderer?.Dispose();
                _blurTexture?.Dispose();
                _blurTarget?.Dispose();
                _layer1Texture?.Dispose();
                _layer1Target?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
            }
        }
Ejemplo n.º 6
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.</summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                Show();

                Cursor.Current = Cursors.WaitCursor;

                Initialize();

                _originalSize = new DX.Vector2(GroupControl1.ClientSize.Width, GroupControl2.ClientSize.Height);

                GorgonApplication.IdleMethod = Idle;
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
                GorgonApplication.Quit();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Ejemplo n.º 7
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                GorgonApplication.Run(Initialize(), Idle);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();

                foreach (GorgonTexture2D texture in _textures)
                {
                    texture?.Dispose();
                }

                _renderer?.Dispose();
                _depthBuffer?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
                _assemblyCache?.Dispose();
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Function to perform clean up operations.
 /// </summary>
 private static void CleanUp()
 {
     GorgonExample.UnloadResources();
     _window?.Dispose();
     _fontFactory?.Dispose();
     _graphics?.Dispose();
 }
Ejemplo n.º 9
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                GorgonApplication.Run(Initialize(), Idle);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();

                _lightEffect?.Dispose();
                _renderer?.Dispose();
                _finalTexture?.Dispose();
                _finalTarget?.Dispose();
                _backgroundLogoTexture?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 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()
        {
            _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);
        }
Ejemplo n.º 12
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                GorgonApplication.Run(Initialize(), Idle);

                if (_mp3Player != null)
                {
                    _mp3Player.Stop();
                }
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();

                _mp3Player.Dispose();
                _renderer?.Dispose();
                _trooper?.Dispose();
                _metal?.Dispose();
                _targetView?.Dispose();
                _target?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Function to load true type fonts to generate from.
        /// </summary>
        /// <param name="window">The window containing the loading message.</param>
        /// <returns>The font families to use when building the bitmap fonts.</returns>
        private static IReadOnlyList <Drawing.FontFamily> LoadTrueTypeFonts(FormMain window)
        {
            // Load in a bunch of true type fonts.
            DirectoryInfo dirInfo = GorgonExample.GetResourcePath("Fonts");

            FileInfo[] files = dirInfo.GetFiles("*.ttf", SearchOption.TopDirectoryOnly);

            var fontFamilies = new List <Drawing.FontFamily>();

            // Load all external true type fonts for this example.
            // This takes a while...
            foreach (FileInfo file in files)
            {
                window.UpdateStatus($"Loading Font: {file.FullName}".Ellipses(50));
                Drawing.FontFamily externFont = _fontFactory.LoadTrueTypeFontFamily(file.FullName);
                _fontFamilies.Insert(0, externFont.Name);
                fontFamilies.Add(externFont);
            }

            window.UpdateStatus(null);

            fontFamilies.AddRange(Drawing.FontFamily.Families);

            return(fontFamilies);
        }
Ejemplo n.º 14
0
        private static void Main()
        {
            Log = new GorgonLog("Writing", "Tape_Worm");

            Log.LogStart();

            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                WriteDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "Writing"));

                if (!WriteDirectory.Exists)
                {
                    WriteDirectory.Create();
                    WriteDirectory.Refresh();
                }

                Application.Run(new Form());
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                Log.LogEnd();
            }
        }
Ejemplo n.º 15
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                GorgonApplication.Run(Initialize(), Idle);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();

                _gaussBlur?.Dispose();
                _oldFilm?.Dispose();
                _displacement?.Dispose();
                _finalView?.Dispose();
                _finalTarget?.Dispose();
                _postView2?.Dispose();
                _postTarget2?.Dispose();
                _postView1?.Dispose();
                _postTarget1?.Dispose();
                _background?.Dispose();
                _renderer?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load"></see> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GorgonExample.ShowStatistics = false;
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                Show();
                Application.DoEvents();

                // Initialize Gorgon
                // Set it up so that we won't be rendering in the background, but allow the screensaver to activate.
                IReadOnlyList <IGorgonVideoAdapterInfo> adapters = GorgonGraphics.EnumerateAdapters(log: GorgonApplication.Log);
                if (adapters.Count == 0)
                {
                    throw new GorgonException(GorgonResult.CannotCreate,
                                              "No suitable video adapter found in the system.\nGorgon requires a minimum of a Direct3D 11.4 capable video device.");
                }

                _graphics = new GorgonGraphics(adapters[0]);

                // Set the video mode.
                ClientSize = new Size(640, 400);
                _screen    = new GorgonSwapChain(_graphics,
                                                 this,
                                                 new GorgonSwapChainInfo("FunWithShapes SwapChain")
                {
                    Width  = ClientSize.Width,
                    Height = ClientSize.Height,
                    Format = BufferFormat.R8G8B8A8_UNorm
                });
                _screen.AfterSwapChainResized += Screen_AfterSwapChainResized;
                _graphics.SetRenderTarget(_screen.RenderTargetView);
                _halfSize = new DX.Size2F(_screen.Width / 2.0f, _screen.Height / 2.0f);

                // Create our 2D renderer so we can draw stuff.
                _renderer = new Gorgon2D(_graphics);

                LabelPleaseWait.Visible = false;

                GorgonExample.LoadResources(_graphics);

                // Draw the image.
                DrawAPrettyPicture();
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
                GorgonApplication.Quit();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Function to initialize the application.
        /// </summary>
        /// <returns>The main window for the application.</returns>
        private static FormMain Initialize()
        {
            GorgonExample.ResourceBaseDirectory = new DirectoryInfo(Settings.Default.ResourceLocation);

            FormMain window = GorgonExample.Initialize(new DX.Size2(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height), "Fonts");

            try
            {
                IReadOnlyList <IGorgonVideoAdapterInfo> videoDevices = GorgonGraphics.EnumerateAdapters(log: GorgonApplication.Log);

                if (videoDevices.Count == 0)
                {
                    throw new GorgonException(GorgonResult.CannotCreate,
                                              "Gorgon requires at least a Direct3D 11.4 capable video device.\nThere is no suitable device installed on the system.");
                }

                // Find the best video device.
                _graphics = new GorgonGraphics(videoDevices.OrderByDescending(item => item.FeatureSet).First());

                _screen = new GorgonSwapChain(_graphics,
                                              window,
                                              new GorgonSwapChainInfo("Gorgon2D Effects Example Swap Chain")
                {
                    Width  = Settings.Default.Resolution.Width,
                    Height = Settings.Default.Resolution.Height,
                    Format = BufferFormat.R8G8B8A8_UNorm
                });

                // Tell the graphics API that we want to render to the "screen" swap chain.
                _graphics.SetRenderTarget(_screen.RenderTargetView);

                // Initialize the renderer so that we are able to draw stuff.
                _renderer = new Gorgon2D(_graphics);

                // Load our logo.
                GorgonExample.LoadResources(_graphics);

                // We need to create a font factory so we can create/load (and cache) fonts.
                _fontFactory = new GorgonFontFactory(_graphics);

                // Create our fonts.
                GenerateGorgonFonts(LoadTrueTypeFonts(window), window);

                // Build our text sprite.
                _text = new GorgonTextSprite(_fontFactory.DefaultFont, Resources.Lorem_Ipsum)
                {
                    LineSpace = 0
                };

                return(window);
            }
            finally
            {
                GorgonExample.EndInit();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Function to initialize the application.
        /// </summary>
        /// <returns>The main window for the application.</returns>
        private static FormMain Initialize()
        {
            GorgonExample.ResourceBaseDirectory = new DirectoryInfo(Settings.Default.ResourceLocation);
            FormMain window =
                GorgonExample.Initialize(new DX.Size2(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height), "Polygonal Sprites");

            try
            {
                IReadOnlyList <IGorgonVideoAdapterInfo> videoDevices = GorgonGraphics.EnumerateAdapters(log: GorgonApplication.Log);

                if (videoDevices.Count == 0)
                {
                    throw new GorgonException(GorgonResult.CannotCreate,
                                              "Gorgon requires at least a Direct3D 11.4 capable video device.\nThere is no suitable device installed on the system.");
                }

                // Find the best video device.
                _graphics = new GorgonGraphics(videoDevices.OrderByDescending(item => item.FeatureSet).First());

                _screen = new GorgonSwapChain(_graphics,
                                              window,
                                              new GorgonSwapChainInfo("Gorgon2D Effects Example Swap Chain")
                {
                    Width  = Settings.Default.Resolution.Width,
                    Height = Settings.Default.Resolution.Height,
                    Format = BufferFormat.R8G8B8A8_UNorm
                });

                // Tell the graphics API that we want to render to the "screen" swap chain.
                _graphics.SetRenderTarget(_screen.RenderTargetView);

                // Initialize the renderer so that we are able to draw stuff.
                _renderer = new Gorgon2D(_graphics);

                _texture = GorgonTexture2DView.FromFile(_graphics,
                                                        GetResourcePath(@"Textures\PolySprites\Ship.png"),
                                                        new GorgonCodecPng(),
                                                        new GorgonTexture2DLoadOptions
                {
                    Binding = TextureBinding.ShaderResource,
                    Name    = "Ship Texture",
                    Usage   = ResourceUsage.Immutable
                });

                GorgonExample.LoadResources(_graphics);

                CreateSprites();

                return(window);
            }
            finally
            {
                GorgonExample.EndInit();
            }
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.</summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data. </param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            GorgonExample.UnloadResources();

            _renderer?.Dispose();
            _leftPanel?.Dispose();
            _rightPanel?.Dispose();
            _graphics?.Dispose();
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                GorgonApplication.Run(new Form());
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
        }
Ejemplo n.º 24
0
        public static async Task Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Application.DoEvents();

                // This is necessary to get winforms to play nice with our background thread prior to running the application.
                WindowsFormsSynchronizationContext.AutoInstall = false;
                SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());

                FormMain window = GorgonExample.Initialize(new DX.Size2(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height), "Space Scene",
                                                           async(sender, _) => await InitializeAsync(sender as FormMain));

                GorgonApplication.Run(window);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                // Always perform your clean up.
                if (_keyboard != null)
                {
                    _keyboard.KeyUp -= Keyboard_KeyUp;
                }

                _helpFont?.Dispose();
                _fontFactory?.Dispose();

                GorgonExample.UnloadResources();

                if (_keyboard != null)
                {
                    _input?.UnregisterDevice(_keyboard);
                }
                _input?.Dispose();
                _sceneRenderer?.Dispose();
                _resources?.Dispose();
                _renderer?.Dispose();
                _mainRtv?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
                _assemblyCache?.Dispose();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing"></see> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs"></see> that contains the event data.</param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            GorgonExample.UnloadResources();

            // Perform clean up.
            Gorgon2D        renderer = Interlocked.Exchange(ref _renderer, null);
            GorgonSwapChain screen   = Interlocked.Exchange(ref _screen, null);
            GorgonGraphics  graphics = Interlocked.Exchange(ref _graphics, null);

            renderer?.Dispose();
            screen?.Dispose();
            graphics?.Dispose();
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Function to load the Gorgon pack file provider plugin.
        /// </summary>
        /// <returns>The file system provider.</returns>
        private IGorgonFileSystemProvider LoadGorPackProvider()
        {
            // The Gorgon packed file provider plug in dll.
            const string gorPackDll = "Gorgon.FileSystem.GorPack.dll";
            // The name of the Gorgon packed file plugin.
            const string gorPackPlugInName = "Gorgon.IO.GorPack.GorPackProvider";

            // Like the zip file example, we'll just create the plugin infrastructure, grab the provider object
            // and get rid of the plugin stuff since we won't need it again.
            _assemblyCache = new GorgonMefPlugInCache(GorgonApplication.Log);
            _assemblyCache.LoadPlugInAssemblies(GorgonExample.GetPlugInPath().FullName, gorPackDll);

            var plugIns = new GorgonMefPlugInService(_assemblyCache);

            return(plugIns.GetPlugIn <GorgonFileSystemProvider>(gorPackPlugInName));
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                Initialize();

                GorgonApplication.Run(_window, Idle);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();

                _2DRenderer.Dispose();
                _fontFactory.Dispose();

                _input?.Dispose();

                if (_renderer != null)
                {
                    foreach (Mesh mesh in _renderer.Meshes)
                    {
                        mesh.Dispose();
                    }

                    _renderer.Dispose();
                }

                _icoSphere?.Dispose();
                _clouds?.Dispose();
                _sphere?.Dispose();
                _cube?.Dispose();
                _plane?.Dispose();
                _triangle?.Dispose();

                _swapChain?.Dispose();
                _graphics?.Dispose();
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Function to handle idle time for the application.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            // This will clear the swap chain to the specified color.
            _swap.RenderTargetView.Clear(Color.CornflowerBlue);

            // Draw our triangle.
            _graphics.Submit(_drawCall);

            GorgonExample.BlitLogo(_graphics);

            // Now we flip our buffers on the swap chain.
            // We need to this or we won't see anything at all except the standard window background color. Clearly, we don't want that.
            // This method will take the current frame back buffer and flip it to the front buffer (the window). If we had more than one swap chain tied to multiple
            // windows, then we'd need to do this for every swap chain.
            _swap.Present(1);

            return(true);
        }
Ejemplo n.º 30
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                GorgonApplication.Run(new Form());
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();
            }
        }