Ejemplo n.º 1
0
        internal SDL2_GameWindow(string title, int width, int height) : base(title, width, height)
        {
            SDL.SDL_WindowFlags initFlags = (
                SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL |
                SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN |
                SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS |
                SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS
                );

            // TODO: Support user resizing? SDL2 does not support setting this after window creation, unlike SDL1.2
            // aka FIXME: Once we have SDL_SetWindowResizable, remove this.

            /*if (AllowUserResizing)
             * {
             *  initFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
             * }*/

            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 24);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STENCIL_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);

            SDL.SDL_GL_SetAttribute(
                SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION,
                3
                );
            SDL.SDL_GL_SetAttribute(
                SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION,
                2
                );
            SDL.SDL_GL_SetAttribute(
                SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK,
                (int)SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE
                );

#if DEBUG
            SDL.SDL_GL_SetAttribute(
                SDL.SDL_GLattr.SDL_GL_CONTEXT_FLAGS,
                (int)SDL.SDL_GLcontext.SDL_GL_CONTEXT_DEBUG_FLAG
                );
#endif

            _sdlWindow = SDL.SDL_CreateWindow(
                title,
                SDL.SDL_WINDOWPOS_CENTERED,
                SDL.SDL_WINDOWPOS_CENTERED,
                width,
                height,
                initFlags
                );

            Icon = title;

            _isFullscreen       = false;
            _wantsFullscreen    = false;
            _lastWindowPosition = new Point(SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED);
        }
Ejemplo n.º 2
0
        public override GameWindow CreateWindow(string title)
        {
            SDL.SDL_WindowFlags initFlags = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN |
                                            SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS |
                                            SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS;

            bool useOpenGL = false;

            if (useOpenGL = PrepareGLAttributes())
            {
                initFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;
            }

            var handle = SDL.SDL_CreateWindow(title,
                                              SDL.SDL_WINDOWPOS_CENTERED,
                                              SDL.SDL_WINDOWPOS_CENTERED,
                                              800 /*GraphicsDeviceManager.DefaultBackBufferWidth*/,
                                              600 /*GraphicsDeviceManager.DefaultBackBufferHeight*/,
                                              initFlags);

            if (handle == IntPtr.Zero)
            {
                // TODO: NoSuitableGraphicsDeviceException
                throw new Exception($"NoSuitableGraphicsDeviceException => {SDL.SDL_GetError()}");
            }

            return(new SDLGameWindow(this, handle, $@"\\.\DISPLAY{SDL.SDL_GetWindowDisplayIndex(handle) + 1}"));
        }
Ejemplo n.º 3
0
        public static void InitializeDisplay()
        {
            SDL.SDL_DisableScreenSaver();

            SDL.SDL_WindowFlags displayFlags =
                (SDL.SDL_WindowFlags)
                    (DisplayFlags.Hidden | DisplayFlags.InputFocus | DisplayFlags.MouseFocus);

            DisplHandle = SDL.SDL_CreateWindow(
                "PicoGame",
                SDL.SDL_WINDOWPOS_CENTERED,
                SDL.SDL_WINDOWPOS_CENTERED,
                800,
                600,
                displayFlags);

            if (DisplHandle == IntPtr.Zero)
            {
                throw new Exception("Error creating SDL2 Display: " + SDL.SDL_GetError());
            }

            var info = new SDL.SDL_SysWMinfo();

            SDL.SDL_GetWindowWMInfo(DisplHandle, ref info);

            NativeHandle = info.info.win.window;
        }
Ejemplo n.º 4
0
        public UserInterface(ILogger logger, ITime engineTime, IFileSystem fileSystem, ICommandContext commandContext, EngineClient client,
                             EngineStartupState startupState,
                             bool noOnTop, string windowTitle, SDL.SDL_WindowFlags additionalFlags = 0)
        {
            _logger     = logger ?? throw new ArgumentNullException(nameof(logger));
            _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));

            //Disable to prevent debugger from shutting down the game
            SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");

            if (noOnTop)
            {
                SDL.SDL_SetHint(SDL.SDL_HINT_ALLOW_TOPMOST, "0");
            }

            SDL.SDL_SetHint(SDL.SDL_HINT_VIDEO_X11_XRANDR, "1");
            SDL.SDL_SetHint(SDL.SDL_HINT_VIDEO_X11_XVIDMODE, "1");

            SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING);

            Window = new Window(_logger, _fileSystem, windowTitle, additionalFlags);

            Window.Center();

            Renderer = new Renderer(logger, engineTime, commandContext, fileSystem, this, client, startupState, Framework.Path.Shaders);
        }
Ejemplo n.º 5
0
        public static WindowState ToWindowState(this SDL.SDL_WindowFlags windowFlags)
        {
            if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) ||
                windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_BORDERLESS))
            {
                return(WindowState.FullscreenBorderless);
            }

            if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_MINIMIZED))
            {
                return(WindowState.Minimised);
            }

            if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN))
            {
                return(WindowState.Fullscreen);
            }

            if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED))
            {
                return(WindowState.Maximised);
            }

            return(WindowState.Normal);
        }
Ejemplo n.º 6
0
    static public void Main()
    {
        System.IntPtr window;
        System.Random rand = new System.Random();

        //	SDL.SDL_LogSetPriority(SDL.SDL_LOG_CATEGORY_APPLICATION, SDL.SDL_LOG_PRIORITY_INFO);
        //	SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");

        SDL.SDL_WindowFlags flags = 0;
//	flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;

        if (SDL.SDL_CreateWindowAndRenderer(WindowWidth, WindowHeight, flags, out window, out Renderer) < 0)
        {
            Quit(2);
        }

        SDL.SDL_SetWindowTitle(window, "TestTtf");
        SDL.SDL_ShowCursor(0);

        SDL_ttf.TTF_Init();
        Font = SDL_ttf.TTF_OpenFont("misaki_gothic.ttf", FontSize);

        if (LoadSprite("icon.bmp", Renderer) < 0)
        {
            Quit(2);
        }

        for (int i = 0; i < NumSprites; ++i)
        {
            Positions[i].x  = rand.Next(WindowWidth - Sprite_w);
            Positions[i].y  = rand.Next(WindowHeight - Sprite_h);
            Positions[i].w  = Sprite_w;
            Positions[i].h  = Sprite_h;
            Velocities[i].x = 0;
            Velocities[i].y = 0;
            while (Velocities[i].x == 0 && Velocities[i].y == 0)
            {
                Velocities[i].x = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed;
                Velocities[i].y = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed;
            }
        }

        Done = 0;

        sw.Start();
        while (Done == 0)
        {
            Loop();
        }

        SDL.SDL_DestroyRenderer(Renderer);
        SDL.SDL_DestroyWindow(window);
        SDL.SDL_Quit();

        SDL_ttf.TTF_CloseFont(Font);
        SDL_ttf.TTF_Quit();


        Quit(0);
    }
Ejemplo n.º 7
0
        public static WindowState ToWindowState(this SDL.SDL_WindowFlags windowFlags)
        {
            // NOTE: on macOS, SDL2 does not differentiate between "maximised" and "fullscreen desktop"
            if (windowFlags.HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) ||
                windowFlags.HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_BORDERLESS) ||
                windowFlags.HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED) && RuntimeInfo.OS == RuntimeInfo.Platform.MacOsx)
            {
                return(WindowState.FullscreenBorderless);
            }

            if (windowFlags.HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_MINIMIZED))
            {
                return(WindowState.Minimised);
            }

            if (windowFlags.HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN))
            {
                return(WindowState.Fullscreen);
            }

            if (windowFlags.HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED))
            {
                return(WindowState.Maximised);
            }

            return(WindowState.Normal);
        }
Ejemplo n.º 8
0
 public GameCreateInfo()
 {
     Height      = 1080;
     Width       = 1920;
     View        = new Meteora3DView();
     AppName     = "Meteora Window";
     WindowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN;
 }
Ejemplo n.º 9
0
        public SDLWindow(string Title)
        {
            SDL.SDL_WindowFlags Flags = SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;

            myPtr = SDL.SDL_CreateWindow(Title, SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, 480, 680, Flags);

            CheckPtr();
        }
Ejemplo n.º 10
0
        public IWindow CreateWindow(string title, SDL.SDL_WindowFlags additionalFlags = 0)
        {
            var window = new Window(_logger, _fileSystem, title, additionalFlags);

            _windows.Add(window.WindowHandle, window);

            return(window);
        }
Ejemplo n.º 11
0
        public void Initialize()
        {
            SDL.SDL_WindowFlags window_flags = 0;
            if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_EVENTS) < 0)
            {
                Debug.WriteLine($"Could not init SDL video: {SDL.SDL_GetError()}");
                return;
            }

            if (_fullscreenWindow)
            {
                window_flags = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
            }

            _window = SDL.SDL_CreateWindow(
                "Gamestreaming",
                SDL.SDL_WINDOWPOS_UNDEFINED,
                SDL.SDL_WINDOWPOS_UNDEFINED,
                _rectOrigin.w, _rectOrigin.h,
                window_flags | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL
                );

            SDL.SDL_SetWindowIcon(
                _window,
                SDL_image.IMG_Load($"{AppDomain.CurrentDomain.BaseDirectory}/Images/icon.png")
                );

            if (_window == IntPtr.Zero)
            {
                // In the case that the window could not be made...
                Debug.WriteLine($"Could not create window: {SDL.SDL_GetError()}");
                return;
            }

            _renderer = SDL.SDL_CreateRenderer(_window,
                                               index: -1,
                                               flags: (SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC));

            if (_renderer == IntPtr.Zero)
            {
                Debug.WriteLine($"Could not create renderer: {SDL.SDL_GetError()}");
                return;
            }

            _texture = SDL.SDL_CreateTexture(_renderer,
                                             SDL.SDL_PIXELFORMAT_YV12,
                                             (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING, _rectOrigin.w, _rectOrigin.h
                                             );

            if (_texture == IntPtr.Zero)
            {
                Debug.WriteLine($"Could not create texture: {SDL.SDL_GetError()}");
                return;
            }

            ShowLoadingScreen();
        }
Ejemplo n.º 12
0
 public SDL2Window(
     string title = "SDL2 Window",
     int x        = SDL.SDL_WINDOWPOS_CENTERED, int y = SDL.SDL_WINDOWPOS_CENTERED,
     int width    = 800, int height = 600,
     SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN
     )
 {
     Init(title, x, y, width, height, flags);
 }
Ejemplo n.º 13
0
        public override void EndScreenDeviceChange(
            string screenDeviceName,
            int clientWidth,
            int clientHeight
            )
        {
            // Set screen device name, not that we use it...
            INTERNAL_deviceName = screenDeviceName;

            // Fullscreen (Note: this only reads the fullscreen flag)
            SDL.SDL_SetWindowFullscreen(INTERNAL_sdlWindow, (uint)INTERNAL_sdlWindowFlags_Next);

            // Bordered
            SDL.SDL_SetWindowBordered(
                INTERNAL_sdlWindow,
                IsBorderless ? SDL.SDL_bool.SDL_FALSE : SDL.SDL_bool.SDL_TRUE
                );

            /* Because Mac windows resizes from the bottom, we have to get the position before changing
             * the size so we can keep the window centered when resizing in windowed mode.
             */
            int prevX = 0;
            int prevY = 0;

            if ((INTERNAL_sdlWindowFlags_Next & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) == 0)
            {
                SDL.SDL_GetWindowPosition(INTERNAL_sdlWindow, out prevX, out prevY);
            }

            // Window bounds
            SDL.SDL_SetWindowSize(INTERNAL_sdlWindow, clientWidth, clientHeight);

            // Window position
            if ((INTERNAL_sdlWindowFlags_Current & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP &&
                (INTERNAL_sdlWindowFlags_Next & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) == 0)
            {
                // If exiting fullscreen, just center the window on the desktop.
                SDL.SDL_SetWindowPosition(
                    INTERNAL_sdlWindow,
                    SDL.SDL_WINDOWPOS_CENTERED,
                    SDL.SDL_WINDOWPOS_CENTERED
                    );
            }
            else if ((INTERNAL_sdlWindowFlags_Next & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) == 0)
            {
                SDL.SDL_SetWindowPosition(
                    INTERNAL_sdlWindow,
                    prevX + ((OpenGLDevice.Instance.Backbuffer.Width - clientWidth) / 2),
                    prevY + ((OpenGLDevice.Instance.Backbuffer.Height - clientHeight) / 2)
                    );
            }

            // Current flags have just been updated.
            INTERNAL_sdlWindowFlags_Current = INTERNAL_sdlWindowFlags_Next;
        }
Ejemplo n.º 14
0
        public Window(string title, int w, int h, SDL.SDL_WindowFlags flags)
        {
            window = SDL.SDL_CreateWindow(title, SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, w, h, flags);
            if (window == IntPtr.Zero)
            {
                Console.WriteLine($"There was an issue creating the window. {SDL.SDL_GetError()}");
                Environment.Exit(-1);
            }

            WIDTH = w; HEIGHT = h;
        }
Ejemplo n.º 15
0
        public static void CreateWindowAndRenderer(int Width, int Height, SDL.SDL_WindowFlags Window_flags, out SDLWindow Window, out SDLRenderer Renderer)
        {
            IntPtr WindowPtr;

            IntPtr RendererPtr;

            ThrowIfResultIsError(SDL.SDL_CreateWindowAndRenderer(Width, Height, Window_flags, out WindowPtr, out RendererPtr));

            Window = new SDLWindow(WindowPtr);

            Renderer = new SDLRenderer(RendererPtr);
        }
Ejemplo n.º 16
0
 public ImGuiSDL2CSWindow(
     string title = "ImGui.NET-SDL2-CS Window",
     int x        = SDL.SDL_WINDOWPOS_CENTERED, int y = SDL.SDL_WINDOWPOS_CENTERED,
     int width    = 800, int height = 600,
     SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN
     ) : base(title, x, y, width, height, flags)
 {
     _IsSuperClass = GetType() == typeof(ImGuiSDL2CSWindow);
     ImGuiSDL2CSHelper.Init();
     OnEvent = ImGuiOnEvent;
     OnLoop  = ImGuiOnLoop;
 }
Ejemplo n.º 17
0
 public override void BeginScreenDeviceChange(bool willBeFullScreen)
 {
     // Fullscreen windowflag
     if (willBeFullScreen)
     {
         INTERNAL_sdlWindowFlags_Next |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
     }
     else
     {
         INTERNAL_sdlWindowFlags_Next &= ~SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
     }
 }
Ejemplo n.º 18
0
    static public void Main()
    {
        System.IntPtr window;
        System.Random rand = new System.Random();

        //SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");

        SDL.SDL_WindowFlags flags = 0;
        //	flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;

        if (SDL.SDL_CreateWindowAndRenderer(WindowWidth, WindowHeight, flags, out window, out Renderer) < 0)
        {
            Quit(2);
        }

        SDL.SDL_SetWindowTitle(window, "TestSpriteMinimal");


        if (LoadSprite("icon.png", Renderer) < 0)
        {
            Quit(2);
            return;
        }


        for (int i = 0; i < NumSprites; ++i)
        {
            Positions[i].x  = rand.Next(WindowWidth - Sprite_w);
            Positions[i].y  = rand.Next(WindowHeight - Sprite_h);
            Positions[i].w  = Sprite_w;
            Positions[i].h  = Sprite_h;
            Velocities[i].x = 0;
            Velocities[i].y = 0;
            while (Velocities[i].x == 0 && Velocities[i].y == 0)
            {
                Velocities[i].x = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed;
                Velocities[i].y = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed;
            }
        }

        Done = 0;

        while (Done == 0)
        {
            Loop();
        }

        SDL.SDL_DestroyRenderer(Renderer);
        SDL.SDL_DestroyWindow(window);
        SDL.SDL_Quit();

        Quit(0);
    }
Ejemplo n.º 19
0
        /// <summary>
        ///  Create a new SDL surface.
        /// </summary>
        /// <param name="surface">Pointer to unmanaged SDL_Surface.</param>
        internal SDLWindow(string windowTitle,
                           int x,
                           int y,
                           int width,
                           int height)
        {
            SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN;
            mWindow = SDL.SDL_CreateWindow(windowTitle, x, y, width, height, flags);

            if (mWindow == IntPtr.Zero)
            {
                throw new SDLException("Failed to create main window");
            }
        }
Ejemplo n.º 20
0
        public IWindow CreateMainWindow(string title, SDL.SDL_WindowFlags additionalFlags = 0, bool recreate = false)
        {
            if (MainWindow != null)
            {
                if (!recreate)
                {
                    throw new InvalidOperationException("Cannot recreate main window when recreate is not requested");
                }

                DestroyMainWindow();
            }

            MainWindow = WindowManager.CreateWindow(title, additionalFlags);

            return(MainWindow);
        }
Ejemplo n.º 21
0
        internal SDL2_GameWindow()
        {
            SDL.SDL_WindowFlags initFlags = (
                SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL |
                SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN |
                SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS |
                SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS
                );

            // FIXME: Once we have SDL_SetWindowResizable, remove this. -flibit
            if (AllowUserResizing)
            {
                initFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
            }

            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 24);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STENCIL_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
#if DEBUG
            SDL.SDL_GL_SetAttribute(
                SDL.SDL_GLattr.SDL_GL_CONTEXT_FLAGS,
                (int)SDL.SDL_GLcontext.SDL_GL_CONTEXT_DEBUG_FLAG
                );
#endif

            string title = MonoGame.Utilities.AssemblyHelper.GetDefaultWindowTitle();
            INTERNAL_sdlWindow = SDL.SDL_CreateWindow(
                title,
                SDL.SDL_WINDOWPOS_CENTERED,
                SDL.SDL_WINDOWPOS_CENTERED,
                GraphicsDeviceManager.DefaultBackBufferWidth,
                GraphicsDeviceManager.DefaultBackBufferHeight,
                initFlags
                );
            INTERNAL_SetIcon(title);

            INTERNAL_isFullscreen    = false;
            INTERNAL_wantsFullscreen = false;
        }
Ejemplo n.º 22
0
 public Window(int width, int height, int xPos, int yPos, bool fullscreen, string title)
 {
     Shared.Window = this;
     if (fullscreen)
     {
         _flags = SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
     }
     Running = false;
     if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) == 0)
     {
         _win = SDL.SDL_CreateWindow(title,
                                     xPos,
                                     yPos,
                                     width,
                                     height,
                                     _flags
                                     );
         _renderer       = SDL.SDL_CreateRenderer(_win, -1, 0);
         Shared.Renderer = _renderer;
         // Check if window and render are still equal to null (IntPtr.Zero)
         if (_win != IntPtr.Zero)
         {
             // Window true, check render
             if (_renderer != IntPtr.Zero)
             {
                 Running = true; SDL.SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 255);
             }
             else
             {
                 Running = false;
             }
         }
         else
         {
             Running = false;
         }
     }
     else
     {
         Running = false;
     }
 }
Ejemplo n.º 23
0
        internal SDL2_GameWindow()
        {
            INTERNAL_sdlWindowFlags_Next = (
                SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL |
                SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN |
                SDL.SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS |
                SDL.SDL_WindowFlags.SDL_WINDOW_MOUSE_FOCUS
                );
#if RESIZABLE_WINDOW
            AllowUserResizing = true;
#else
            AllowUserResizing = false;
#endif

            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 24);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STENCIL_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
#if DEBUG
            SDL.SDL_GL_SetAttribute(
                SDL.SDL_GLattr.SDL_GL_CONTEXT_FLAGS,
                (int)SDL.SDL_GLcontext.SDL_GL_CONTEXT_DEBUG_FLAG
                );
#endif

            string title = MonoGame.Utilities.AssemblyHelper.GetDefaultWindowTitle();
            INTERNAL_sdlWindow = SDL.SDL_CreateWindow(
                title,
                SDL.SDL_WINDOWPOS_CENTERED,
                SDL.SDL_WINDOWPOS_CENTERED,
                GraphicsDeviceManager.DefaultBackBufferWidth,
                GraphicsDeviceManager.DefaultBackBufferHeight,
                INTERNAL_sdlWindowFlags_Next
                );
            INTERNAL_SetIcon(title);

            INTERNAL_sdlWindowFlags_Current = INTERNAL_sdlWindowFlags_Next;
        }
Ejemplo n.º 24
0
        public Window(string title, int left, int top, int width, int height, SDL.SDL_WindowFlags flags, bool createRenderer = false)
        {
            this.Title  = title;
            this.Left   = left;
            this.Top    = top;
            this.Width  = width;
            this.Height = height;
            this.Flags  = flags;
            this.IntPtr = SDL.CreateWindow(title, left, top, width, height, flags);
            if (createRenderer)
            {
                //IntPtr windowIntPtr;// = new IntPtr();
                //IntPtr rendrerIntPtr;// = new IntPtr();

                //var rv=SDL.CreateWindowAndRenderer(width, height, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN, out windowIntPtr, out rendrerIntPtr);
                //if (Convert.ToBoolean(windowIntPtr.ToInt64()) && Convert.ToBoolean(rendrerIntPtr.ToInt64()))
                //{
                //this.Renderer = new Renderer() { IntPtr = rendrerIntPtr };//
                this.Renderer = (Renderer)SDL.CreateRenderer(this.IntPtr, 0, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED);
                //}
            }
        }
Ejemplo n.º 25
0
    //Creates the screen and renderer or exits the aplication if it fails
    public static void Init(int w = 800, int h = 600, bool fullScreen = false)
    {
        //Flags for the screen
        SDL.SDL_WindowFlags screenFlags = SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN;
        if (fullScreen)
        {
            screenFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
        }

        screen = SDL.SDL_CreateWindow("Roomba Warfare",
                                      SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
                                      w, h, screenFlags);

        //Get the window size (In case we active Fullscreen)
        SDL.SDL_GetWindowSize(screen, out ScreenWidth, out ScreenHeight);

        if (screen == null)
        {
            SDL.SDL_ShowSimpleMessageBox
                (SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "Error",
                "Could not create the screen", screen);
            Environment.Exit(2);
        }

        //Flags for the renderer, vsync active
        SDL.SDL_RendererFlags rendererFlags =
            SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED |
            SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC;

        Renderer = SDL.SDL_CreateRenderer(screen, -1, rendererFlags);

        if (Renderer == null)
        {
            SDL.SDL_ShowSimpleMessageBox
                (SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "Error",
                "Could not create the renderer", screen);
            Environment.Exit(2);
        }
    }
Ejemplo n.º 26
0
        public void Init(
            string title = "SDL2 Window",
            int x        = SDL.SDL_WINDOWPOS_CENTERED, int y = SDL.SDL_WINDOWPOS_CENTERED,
            int width    = 800, int height = 600,
            SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN
            )
        {
            SDL2Helper.Init();

            if (_Handle != IntPtr.Zero)
            {
                throw new InvalidOperationException("SDL2Window already initialized, Dispose() first before reusing!");
            }

            _Handle = SDL.SDL_CreateWindow(title, x, y, width, height, flags);

            if ((flags & SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL) == SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL)
            {
                _GLContext = SDL.SDL_GL_CreateContext(_Handle);
                SDL.SDL_GL_MakeCurrent(_Handle, _GLContext);
            }
        }
Ejemplo n.º 27
0
        private void CreateWindow(string title, int x, int y, int width, int height, VideoMode mode)
        {
            videoMode = mode;

            if (x == int.MaxValue)
            {
                x = SDL.SDL_WINDOWPOS_CENTERED;
            }
            if (y == int.MaxValue)
            {
                y = SDL.SDL_WINDOWPOS_CENTERED;
            }

            SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN & SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;
            if (mode == VideoMode.Borderless)
            {
                flags |= SDL.SDL_WindowFlags.SDL_WINDOW_BORDERLESS;
            }
            else if (mode == VideoMode.Fullscreen)
            {
                flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
            }

            handle = SDL.SDL_CreateWindow(title, x, y, width, height, flags);

            if (handle == IntPtr.Zero)
            {
                throw new ApplicationException("SDL_CreateWindow failed: " + SDL.SDL_GetError());
            }

            // Windows only: spawning settings window early may cause
            // the game window to not appear on foreground.
            Focus();

            Title = title;
        }
Ejemplo n.º 28
0
        public bool IsWindowMaximized()
        {
            SDL.SDL_WindowFlags flags = (SDL.SDL_WindowFlags)SDL.SDL_GetWindowFlags(Window.Handle);

            return((flags & SDL_WindowFlags.SDL_WINDOW_MAXIMIZED) != 0);
        }
Ejemplo n.º 29
0
        private void InitializeSDL()
        {
            SetProcessDPIAware();

            DoUpdateDisplayScale();

            int retVal = 0;

            // Get SDL humming
            if ((retVal = SDL.SDL_Init(SDL.SDL_INIT_VIDEO)) < 0)
            {
                throw new InvalidOperationException(String.Format("SDL_Init failed.  Error {0:x}", retVal));
            }

            //
            if (SDL.SDL_SetHint(SDL.SDL_HINT_RENDER_SCALE_QUALITY, "0") == SDL.SDL_bool.SDL_FALSE)
            {
                throw new InvalidOperationException("SDL_SetHint failed to set scale quality.");
            }

            SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN;

            _sdlWindow = SDL.SDL_CreateWindow(
                "Imlac PDS-1",
                SDL.SDL_WINDOWPOS_UNDEFINED,
                SDL.SDL_WINDOWPOS_UNDEFINED,
                _xResolution,
                _yResolution,
                _fullScreen ? SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP | flags : flags);


            if (_sdlWindow == IntPtr.Zero)
            {
                throw new InvalidOperationException("SDL_CreateWindow failed.");
            }

            _sdlRenderer = SDL.SDL_CreateRenderer(_sdlWindow, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED);
            if (_sdlRenderer == IntPtr.Zero)
            {
                // Fall back to software
                _sdlRenderer = SDL.SDL_CreateRenderer(_sdlWindow, -1, SDL.SDL_RendererFlags.SDL_RENDERER_SOFTWARE);

                if (_sdlRenderer == IntPtr.Zero)
                {
                    // Still no luck.
                    throw new InvalidOperationException("SDL_CreateRenderer failed.");
                }
            }

            SDL.SDL_SetRenderDrawBlendMode(_sdlRenderer, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);

            // Clear the screen.
            SDL.SDL_SetRenderDrawColor(_sdlRenderer, 0, 0, 0, 0xff);
            SDL.SDL_RenderFillRect(_sdlRenderer, ref _displayRect);
            SDL.SDL_RenderPresent(_sdlRenderer);

            // Register a User event for rendering and resizing.
            _userEventType       = SDL.SDL_RegisterEvents(1);
            _userEvent           = new SDL.SDL_Event();
            _userEvent.type      = SDL.SDL_EventType.SDL_USEREVENT;
            _userEvent.user.type = _userEventType;
        }
Ejemplo n.º 30
0
        internal override IntPtr OpenWindow(IntVector2 size, string title)
        {
            // init check for multi-window purposes
            if (!_isSdlInitialized)
            {
                if (SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) < 0)
                {
                    throw new GlaivesException($"Failed to initialize SDL: {SDL.SDL_GetError()}");
                }

                _isSdlInitialized = true;
            }

            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);

            SDL.SDL_WindowFlags windowFlags = windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL |
                                                            SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN |
                                                            SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;

            NativeWindowHandle = SDL.SDL_CreateWindow(title, SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, size.X, size.Y, windowFlags);

            if (NativeWindowHandle == IntPtr.Zero)
            {
                throw new GlaivesException($"Failed to open SDL window: {SDL.SDL_GetError()}");
            }

            _isOpen = true;

            _windowInfo =
                OpenTK.Platform.Utilities.CreateSdl2WindowInfo(NativeWindowHandle);
            GraphicsMode graphicsMode = GraphicsMode.Default;

            GlContext = new GraphicsContext(graphicsMode, _windowInfo)
            {
                SwapInterval = 1
            };

            MakeContextCurrent();
            GlContext.LoadAll();

            string glVersion    = GL.GetString(StringName.Version);
            int    currentMajor = int.Parse(glVersion.Split('.')[0][0].ToString());
            int    currentMinor = int.Parse(glVersion.Split('.')[1][0].ToString());

            if (currentMajor < 3)
            {
                throw new NotSupportedException("Your system does not support OpenGL 3.x");
            }
            else if (currentMajor == 3)
            {
                if (currentMinor < 2)
                {
                    throw new NotSupportedException("Your system does not support OpenGL 3.2");
                }
            }

            return(NativeWindowHandle);
        }