Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Context" /> class.
        /// </summary>
        public Context()
        {
            // Create our timer object.
            if (GorgonTimerQpc.SupportsQpc())
            {
                _timer = new GorgonTimerQpc();
            }
            else
            {
                _timer = new GorgonTimerMultimedia();
            }

            // Create the splash screen and the main interface.
            _splashScreen = new formSplash();
            MainForm      = new formMain();                             // Note that we're assign this to the inherited property 'MainForm'.
            // This how the application context knows which form controls the application.

            RunMe();
        }
Beispiel #2
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), "Lights");

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

                // Load in our texture for our logo background.
                _backgroundLogoTexture = GorgonTexture2DView.FromFile(_graphics,
                                                                      Path.Combine(GorgonExample.GetResourcePath(@"Textures\Lights\").FullName, "lights.dds"),
                                                                      new GorgonCodecDds(),
                                                                      new GorgonTexture2DLoadOptions
                {
                    Usage   = ResourceUsage.Immutable,
                    Binding = TextureBinding.ShaderResource,
                    Name    = "Logo"
                });

                _torchTexture = GorgonTexture2DView.FromFile(_graphics,
                                                             Path.Combine(GorgonExample.GetResourcePath(@"Textures\Lights\").FullName, "Torch.png"),
                                                             new GorgonCodecPng(),
                                                             new GorgonTexture2DLoadOptions
                {
                    Usage   = ResourceUsage.Immutable,
                    Binding = TextureBinding.ShaderResource,
                    Name    = "Torch"
                });

                UpdateRenderTarget();

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

                _logoSprite = new GorgonSprite
                {
                    Texture       = _backgroundLogoTexture,
                    Bounds        = new DX.RectangleF(0, 0, _backgroundLogoTexture.Width, _backgroundLogoTexture.Height),
                    TextureRegion = new DX.RectangleF(0, 0, 1, 1),
                    Anchor        = new DX.Vector2(0.5f, 0.5f)
                };

                _torchSprite = new GorgonSprite
                {
                    Texture       = _torchTexture,
                    Bounds        = new DX.RectangleF(0, 0, 55, _torchTexture.Height),
                    TextureRegion = _torchTexture.Texture.ToTexel(new DX.Rectangle(0, 0, 55, _torchTexture.Height)),
                };

                // Create the effect that will light up our sprite(s).
                _lightEffect = new Gorgon2DDeferredLightingEffect(_renderer)
                {
                    FlipYNormal = true // Need this to be true because CrazyBump exported the normal map with Y inverted.
                };

                _lightEffect.Lights.Add(new Gorgon2DLight
                {
                    Color           = new GorgonColor(0.25f, 0.25f, 0.25f),
                    Attenuation     = 75,
                    LightType       = LightType.Point,
                    SpecularEnabled = true,
                    SpecularPower   = 6.0f,
                    Position        = new DX.Vector3((_screen.Width / 2.0f) - 150.0f, (_screen.Height / 2.0f) - 150.0f, -50)
                });
                _lightEffect.Lights.Add(new Gorgon2DLight
                {
                    Color           = GorgonColor.White,
                    Intensity       = 0.075f,
                    LightType       = LightType.Directional,
                    SpecularEnabled = false,
                    Position        = new DX.Vector3(0, 0, -200),
                    LightDirection  = new DX.Vector3(0, 0, 1)
                });

                GorgonExample.LoadResources(_graphics);

                window.MouseMove += Window_MouseMove;
                window.KeyDown   += Window_KeyDown;

                _torchFrameTime = new GorgonTimerQpc();

                return(window);
            }
            finally
            {
                GorgonExample.EndInit();
            }
        }
Beispiel #3
0
 /// <summary>Initializes a new instance of the <see cref="RenderTargetFactory"/> class.</summary>
 /// <param name="graphics">The graphics interface that owns this factory.</param>
 public RenderTargetFactory(GorgonGraphics graphics)
 {
     _graphics    = graphics;
     _expiryTimer = GorgonTimerQpc.SupportsQpc() ? (IGorgonTimer) new GorgonTimerQpc() : new GorgonTimerMultimedia();
 }