예제 #1
0
        /// <summary>
        /// Function to load the logo for display in the application.
        /// </summary>
        /// <param name="graphics">The graphics interface to use.</param>
        public static void LoadResources(GorgonGraphics graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            _factory   = new GorgonFontFactory(graphics);
            _statsFont = _factory.GetFont(new GorgonFontInfo("Segoe UI", 9, FontHeightMode.Points, "Segoe UI 9pt Bold Outlined")
            {
                AntiAliasingMode = FontAntiAliasMode.AntiAlias,
                FontStyle        = FontStyle.Bold,
                OutlineColor1    = GorgonColor.Black,
                OutlineColor2    = GorgonColor.Black,
                OutlineSize      = 2,
                TextureWidth     = 512,
                TextureHeight    = 256
            });

            using (var stream = new MemoryStream(Resources.Gorgon_Logo_Small))
            {
                var ddsCodec = new GorgonCodecDds();
                _logo = GorgonTexture2DView.FromStream(graphics, stream, ddsCodec, options: new GorgonTexture2DLoadOptions
                {
                    Name    = "Gorgon Logo Texture",
                    Binding = TextureBinding.ShaderResource,
                    Usage   = ResourceUsage.Immutable
                });
            }
        }
예제 #2
0
        /// <summary>Imports the data.</summary>
        /// <param name="temporaryDirectory">The temporary directory for writing any transitory data.</param>
        /// <param name="cancelToken">The cancel token.</param>
        /// <remarks>
        /// <para>
        /// The <paramref name="temporaryDirectory"/> should be used to write any working/temporary data used by the import.  Note that all data written into this directory will be deleted when the
        /// project is unloaded from memory.
        /// </para>
        /// </remarks>
        public FileInfo ImportData(DirectoryInfo temporaryDirectory, CancellationToken cancelToken)
        {
            var ddsCodec = new GorgonCodecDds();

            _log.Print($"Importing file '{SourceFile.FullName}' (Codec: {_codec.Name})...", LoggingLevel.Verbose);
            using (IGorgonImage image = _codec.LoadFromFile(SourceFile.FullName))
            {
                var tempFile = new FileInfo(Path.Combine(temporaryDirectory.FullName, Path.GetFileNameWithoutExtension(SourceFile.Name)));

                _log.Print($"Converting '{SourceFile.FullName}' to DDS file format. Image format [{image.Format}].", LoggingLevel.Verbose);
                ddsCodec.SaveToFile(image, tempFile.FullName);

                return(tempFile);
            }
        }
예제 #3
0
        /// <summary>
        /// Function to load the common resources at application start up.
        /// </summary>
        public static void LoadResources()
        {
            IGorgonImageCodec dds = new GorgonCodecDds();

            using (var stream = new MemoryStream(Resources.Bg_Pattern_256x256, false))
            {
                CheckerBoardPatternImage = dds.LoadFromStream(stream);
            }

            using (var stream = new MemoryStream(Resources.manual_input_24x24, false))
            {
                KeyboardIcon = dds.LoadFromStream(stream);
            }

            using (var stream = new MemoryStream(Resources.manual_vertex_edit_64x64, false))
            {
                KeyboardIconLarge = dds.LoadFromStream(stream);
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: ishkang/Gorgon
        /// <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), "Post Processing");

            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);

                GorgonExample.LoadResources(_graphics);

                // Load the Gorgon logo to show in the lower right corner.
                var ddsCodec = new GorgonCodecDds();

                // Import the images we'll use in our post process chain.
                if (!LoadImageFiles(ddsCodec))
                {
                    return(window);
                }

                // Initialize the effects that we'll use for compositing, and the compositor itself.
                InitializeEffects();

                // Set up our quick and dirty GUI.
                _buttons = new Button[_compositor.Passes.Count];
                LayoutGUI();

                // Select a random image to start
                _currentImage = GorgonRandom.RandomInt32(0, _images.Length - 1);

                window.KeyUp     += Window_KeyUp;
                window.MouseUp   += Window_MouseUp;
                window.MouseMove += Window_MouseMove;
                window.MouseDown += Window_MouseDown;
                window.IsLoaded   = true;

                return(window);
            }
            finally
            {
                GorgonExample.EndInit();
            }
        }
예제 #5
0
파일: Program.cs 프로젝트: ishkang/Gorgon
        /// <summary>
        /// Function to load textures from application resources.
        /// </summary>
        private static void LoadTextures()
        {
            // Load standard images from the resource section.
            _renderer.TextureCache["UV"] = Resources.UV.ToTexture2D(_graphics,
                                                                    new GorgonTexture2DLoadOptions
            {
                Name = "UV"
            }).GetShaderResourceView();

            _renderer.TextureCache["Earth"] = Resources.earthmap1k.ToTexture2D(_graphics,
                                                                               new GorgonTexture2DLoadOptions
            {
                Name = "Earth"
            }).GetShaderResourceView();

            _renderer.TextureCache["Earth_Specular"] = Resources.earthspec1k.ToTexture2D(_graphics,
                                                                                         new GorgonTexture2DLoadOptions
            {
                Name = "Earth_Specular"
            }).GetShaderResourceView();

            _renderer.TextureCache["Clouds"] = Resources.earthcloudmap.ToTexture2D(_graphics,
                                                                                   new GorgonTexture2DLoadOptions
            {
                Name = "Clouds"
            }).GetShaderResourceView();

            _renderer.TextureCache["GorgonNormalMap"] = Resources.normalmap.ToTexture2D(_graphics,
                                                                                        new GorgonTexture2DLoadOptions
            {
                Name = "GorgonNormalMap"
            }).GetShaderResourceView();

            // The following images are DDS encoded and require an encoder to read them from the resources.
            var dds = new GorgonCodecDds();

            using (var stream = new MemoryStream(Resources.Rain_Height_NRM))
                using (IGorgonImage image = dds.LoadFromStream(stream))
                {
                    _renderer.TextureCache["Water_Normal"] = image.ToTexture2D(_graphics,
                                                                               new GorgonTexture2DLoadOptions
                    {
                        Name = "Water_Normal"
                    }).GetShaderResourceView();
                }

            using (var stream = new MemoryStream(Resources.Rain_Height_SPEC))
                using (IGorgonImage image = dds.LoadFromStream(stream))
                {
                    _renderer.TextureCache["Water_Specular"] = image.ToTexture2D(_graphics,
                                                                                 new GorgonTexture2DLoadOptions
                    {
                        Name = "Water_Specular"
                    }).GetShaderResourceView();
                }

            using (var stream = new MemoryStream(Resources.earthbump1k_NRM))
                using (IGorgonImage image = dds.LoadFromStream(stream))
                {
                    _renderer.TextureCache["Earth_Normal"] = image.ToTexture2D(_graphics,
                                                                               new GorgonTexture2DLoadOptions
                    {
                        Name = "Earth_Normal"
                    }).GetShaderResourceView();
                }
        }