/// <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), "Effects"); 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 }); _screen.BeforeSwapChainResized += Screen_BeforeSwapChainResized; _screen.AfterSwapChainResized += Screen_AfterSwapChainResized; // 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); // Create the displacement effect used for the "cloaking" effect. _displacement = new Gorgon2DDisplacementEffect(_renderer) { Strength = 0 }; // Create the old film effect for that old timey look. _oldFilm = new Gorgon2DOldFilmEffect(_renderer) { ScrollSpeed = 0.05f }; // Create the gaussian blur effect for that "soft" look. _gaussBlur = new Gorgon2DGaussBlurEffect(_renderer, 9) { BlurRenderTargetsSize = new DX.Size2(_screen.Width / 2, _screen.Height / 2), BlurRadius = 1 }; // The higher # of taps on the blur shader will introduce a stutter on first render, so precache its setup data. _gaussBlur.Precache(); // Load our texture with our space background in it. _background = GorgonTexture2DView.FromFile(_graphics, Path.Combine(GorgonExample.GetResourcePath(@"Textures\").FullName, "HotPocket.dds"), new GorgonCodecDds(), new GorgonTexture2DLoadOptions { Usage = ResourceUsage.Immutable, Binding = TextureBinding.ShaderResource }); // Load up our super space ship image. _spaceShipTexture = GorgonTexture2DView.FromFile(_graphics, Path.Combine(GorgonExample.GetResourcePath(@"Textures\Effects\").FullName, "ship.png"), new GorgonCodecPng(), new GorgonTexture2DLoadOptions { Usage = ResourceUsage.Immutable, Binding = TextureBinding.ShaderResource }); _shipSprite = new GorgonSprite { Texture = _spaceShipTexture, TextureRegion = new DX.RectangleF(0, 0, 1, 1), Anchor = new DX.Vector2(0.5f, 0.5f), Position = new DX.Vector2(_screen.Width / 2.0f, _screen.Height / 2.0f), Size = new DX.Size2F(_spaceShipTexture.Width, _spaceShipTexture.Height) }; BuildRenderTargets(); InitializeBackgroundTexturePositioning(); GorgonExample.LoadResources(_graphics); window.MouseMove += Window_MouseMove; window.MouseWheel += Window_MouseWheel; window.KeyUp += Window_KeyUp; return(window); } finally { GorgonExample.EndInit(); } }
/// <summary> /// Function to release the shaders and the resources allocated to them. /// </summary> public void FreeEffects() { if (_posterizeEffect != null) { _posterizeEffect.Dispose(); _posterizeEffect = null; } if (_grayScaleEffect != null) { _grayScaleEffect.Dispose(); _grayScaleEffect = null; } if (_waveEffect != null) { _waveEffect.Dispose(); _waveEffect = null; } if (_1BitEffect != null) { _1BitEffect.Dispose(); _1BitEffect = null; } if (_sharpenEmbossEffect != null) { _sharpenEmbossEffect.Dispose(); _sharpenEmbossEffect = null; } if (_invertEffect != null) { _invertEffect.Dispose(); _invertEffect = null; } if (_gaussBlurEffect != null) { _gaussBlurEffect.Dispose(); _gaussBlurEffect = null; } if (_sobelEdgeDetectEffect != null) { _sobelEdgeDetectEffect.Dispose(); _sobelEdgeDetectEffect = null; } if (_burnDodgeEffect != null) { _burnDodgeEffect.Dispose(); _burnDodgeEffect = null; } if (_displacementEffect == null) { return; } _displacementEffect.Dispose(); _displacementEffect = null; }