Esempio n. 1
0
        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();
        }
Esempio n. 2
0
 protected void Draw(int x, int y, Vector4?color = null)
 {
     if (x >= 0 && x < this.ScreenWidth && y >= 0 && y < this.ScreenHeight)
     {
         SetColor(color ?? Vector4.One);
         SDLRender.RenderDrawPoint(_renderer, x, y);
     }
 }
Esempio n. 3
0
 private void ReleaseUnmanagedResources()
 {
     SDLRender.DestroyRenderer(_renderer);
     SDLVideo.DestroyWindow(_window);
     SDL.Quit();
 }
Esempio n. 4
0
 protected void ClearScreen(Vector4?color = null)
 {
     SetColor(color ?? GetColor(Color.Cyan));
     SDLRender.RenderClear(_renderer);
 }
Esempio n. 5
0
        protected void DrawLine(int x1, int y1, int x2, int y2, Vector4?col = null)
        {
            SetColor(col ?? Vector4.One);
            SDLRender.RenderDrawLine(_renderer, x1, y1, x2, y2);

            //var dx = x2 - x1;
            //var dy = y2 - y1;
            //var dx1 = Math.Abs(dx);
            //var dy1 = Math.Abs(dy);

            //var px = 2 * dy1 - dx1;
            //var py = 2 * dx1 - dy1;

            //int x;
            //int xe;
            //int y;
            //int ye;

            //if (dy1 <= dx1)
            //{
            //    if (dx >= 0)
            //    {
            //        x = x1;
            //        y = y1;
            //        xe = x2;
            //    }
            //    else
            //    {
            //        x = x2;
            //        y = y2;
            //        xe = x1;
            //    }

            //    Draw(x, y, col);

            //    while (x < xe)
            //    {
            //        x++;
            //        if (px < 0)
            //        {
            //            px += 2 * dy1;
            //        }
            //        else
            //        {
            //            if (dx < 0 && dy < 0 || dx > 0 && dy > 0)
            //            {
            //                y += 1;
            //            }
            //            else
            //            {
            //                y -= 1;
            //            }

            //            px += 2 * (dy1 - dx1);
            //        }

            //        Draw(x, y, col);
            //    }
            //}
            //else
            //{
            //    if (dy >= 0)
            //    {
            //        x = x1;
            //        y = y1;
            //        ye = y2;
            //    }
            //    else
            //    {
            //        x = x2;
            //        y = y2;
            //        ye = y1;
            //    }

            //    Draw(x, y, col);

            //    while (y < ye)
            //    {
            //        y += 1;
            //        if (py <= 0)
            //        {
            //            py += 2 * dx1;
            //        }
            //        else
            //        {
            //            if (dx < 0 && dy < 0 || dx > 0 && dy > 0)
            //            {
            //                x += 1;
            //            }
            //            else
            //            {
            //                x -= 1;
            //            }
            //            py += 2 * (dx1 - dy1);
            //        }
            //        Draw(x, y, col);
            //    }
            //}
        }
Esempio n. 6
0
 private void SetColor(Vector4 color)
 {
     SDLRender.SetRenderDrawColor(_renderer, (byte)(color.X * 255), (byte)(color.Y * 255), (byte)(color.Z * 255), (byte)(color.W * 255));
 }
Esempio n. 7
0
 protected void PresentFrame()
 {
     SDLRender.RenderPresent(_renderer);
 }