private void Initialize()
        {
            if (SDL.Init((uint)InitFlags.SDL_INIT_VIDEO) != 0)
            {
                throw new InvalidOperationException("Failed to init SDL");
            }

            // TODO: enable mouse input

            _window = SDLVideo.CreateWindow("Hello World!", 30, 30, ScreenWidth, ScreenHeight, (uint)(WindowFlags.WINDOW_SHOWN | WindowFlags.WINDOW_RESIZABLE));
            if (_window == null)
            {
                SDL.Quit();
                throw new InvalidOperationException("Failed to create window");
            }

            _renderer = SDLRender.CreateRenderer(_window, -1,
                                                 (uint)(RendererFlags.RENDERER_ACCELERATED));

            if (_renderer == null)
            {
                SDL.Quit();
                throw new InvalidOperationException("Failed to create renderer");
            }

            this.OnInitialize();
        }
        public void Run()
        {
            this.Initialize();

            this.Active = true;
            SDLMouse.ShowCursor(0);

            double t1 = Stopwatch.GetTimestamp();

            //var evnt = new Event();
            while (this.Active)
            {
                // Handle Timing
                double t2           = Stopwatch.GetTimestamp();
                var    elapsedTicks = t2 - t1;
                var    elapsed      = elapsedTicks / TimeSpan.TicksPerMillisecond;
                var    elapsedS     = elapsedTicks / TimeSpan.TicksPerSecond;
                t1 = t2;

                // Handle Keyboard Input

                _lastKeys = _keys;
                _keys     = SDLKeyboard.GetKeyboardState().ToArray();

                // Handle events - we only care about mouse clicks and movement
                while (SDLEvents.PollEvent2(out var evnt) != 0)
                {
                    switch (evnt.Type)
                    {
                    case (uint)EventType.QUIT:
                        break;

                    case (uint)EventType.KEYDOWN:
                        continue;

                    default:
                        Console.WriteLine($"Event: {evnt.Type}");
                        continue;
                    }

                    this.Active = false;
                    break;
                }

                if (!this.OnUpdate(elapsedS))
                {
                    this.Active = false;
                }

                SDLVideo.SetWindowTitle(_window, $"Console Game Engine - FPS: {1.0 / elapsedS:F4}");

                PresentFrame();
            }

            SDLMouse.ShowCursor(1);
        }
 private void ReleaseUnmanagedResources()
 {
     SDLRender.DestroyRenderer(_renderer);
     SDLVideo.DestroyWindow(_window);
     SDL.Quit();
 }