Esempio n. 1
0
        public Sdl2GraphicsDevice(Size windowSize, WindowMode windowMode)
        {
            size = windowSize;

            SDL.SDL_Init(SDL.SDL_INIT_NOPARACHUTE | SDL.SDL_INIT_VIDEO);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
            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, 0);

            SDL.SDL_DisplayMode display;
            SDL.SDL_GetCurrentDisplayMode(0, out display);

            Console.WriteLine("Desktop resolution: {0}x{1}", display.w, display.h);
            if (size.Width == 0 && size.Height == 0)
            {
                Console.WriteLine("No custom resolution provided, using desktop resolution");
                size = new Size(display.w, display.h);
            }

            Console.WriteLine("Using resolution: {0}x{1}", size.Width, size.Height);

            window = SDL.SDL_CreateWindow("OpenRA", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, size.Width, size.Height, SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL);

            if (Game.Settings.Game.LockMouseWindow)
                GrabWindowMouseFocus();
            else
                ReleaseWindowMouseFocus();

            if (windowMode == WindowMode.Fullscreen)
                SDL.SDL_SetWindowFullscreen(window, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN);
            else if (windowMode == WindowMode.PseudoFullscreen)
            {
                // Work around a visual glitch in OSX: the window is offset
                // partially offscreen if the dock is at the left of the screen
                if (Platform.CurrentPlatform == PlatformType.OSX)
                    SDL.SDL_SetWindowPosition(window, 0, 0);

                SDL.SDL_SetWindowFullscreen(window, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP);
                SDL.SDL_SetHint(SDL.SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
            }

            SDL.SDL_ShowCursor(0);
            context = SDL.SDL_GL_CreateContext(window);
            SDL.SDL_GL_MakeCurrent(window, context);
            GL.LoadAll();
            ErrorHandler.CheckGlVersion();
            ErrorHandler.CheckGlError();

            if (SDL.SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object") == SDL.SDL_bool.SDL_FALSE)
            {
                ErrorHandler.WriteGraphicsLog("OpenRA requires the OpenGL extension GL_EXT_framebuffer_object.\n"
                    + "Please try updating your GPU driver to the latest version provided by the manufacturer.");
                throw new InvalidProgramException("Missing OpenGL extension GL_EXT_framebuffer_object. See graphics.log for details.");
            }

            GL.EnableClientState(ArrayCap.VertexArray);
            ErrorHandler.CheckGlError();
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            ErrorHandler.CheckGlError();

            SDL.SDL_SetModState(0);
            input = new Sdl2Input();
        }
Esempio n. 2
0
        public Sdl2GraphicsDevice(Size windowSize, WindowMode windowMode)
        {
            size = windowSize;

            SDL.SDL_Init(SDL.SDL_INIT_NOPARACHUTE | SDL.SDL_INIT_VIDEO);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
            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, 0);

            var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;

            if (windowMode == WindowMode.Fullscreen)
            {
                windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
            }
            else if (windowMode == WindowMode.PseudoFullscreen)
            {
                windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
                Environment.SetEnvironmentVariable("SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", "0");
            }

            SDL.SDL_DisplayMode display;
            SDL.SDL_GetCurrentDisplayMode(0, out display);

            Console.WriteLine("Desktop resolution: {0}x{1}", display.w, display.h);
            if (size.Width == 0 && size.Height == 0)
            {
                Console.WriteLine("No custom resolution provided, using desktop resolution");
                size = new Size(display.w, display.h);
            }

            Console.WriteLine("Using resolution: {0}x{1}", size.Width, size.Height);

            window = SDL.SDL_CreateWindow("OpenRA", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, size.Width, size.Height, windowFlags);

            SDL.SDL_ShowCursor(0);
            SDL.SDL_GL_CreateContext(window);
            ErrorHandler.CheckGlError();

            var extensions = Gl.glGetString(Gl.GL_EXTENSIONS);

            if (extensions == null)
            {
                Console.WriteLine("Failed to fetch GL_EXTENSIONS, this is bad.");
            }

            var missingExtensions = requiredExtensions.Where(r => !extensions.Contains(r)).ToArray();

            if (missingExtensions.Any())
            {
                ErrorHandler.WriteGraphicsLog("Unsupported GPU: Missing extensions: {0}".F(missingExtensions.JoinWith(",")));
                throw new InvalidProgramException("Unsupported GPU. See graphics.log for details.");
            }

            Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
            ErrorHandler.CheckGlError();
            Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
            ErrorHandler.CheckGlError();

            SDL.SDL_SetModState(0);
            input = new Sdl2Input();
        }
Esempio n. 3
0
        public Sdl2GraphicsDevice(Size windowSize, WindowMode windowMode)
        {
            size = windowSize;

            SDL.SDL_Init(SDL.SDL_INIT_NOPARACHUTE | SDL.SDL_INIT_VIDEO);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
            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, 0);

            SDL.SDL_DisplayMode display;
            SDL.SDL_GetCurrentDisplayMode(0, out display);

            Console.WriteLine("Desktop resolution: {0}x{1}", display.w, display.h);
            if (size.Width == 0 && size.Height == 0)
            {
                Console.WriteLine("No custom resolution provided, using desktop resolution");
                size = new Size(display.w, display.h);
            }

            Console.WriteLine("Using resolution: {0}x{1}", size.Width, size.Height);

            window = SDL.SDL_CreateWindow("OpenRA", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, size.Width, size.Height, SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL);

            if (Game.Settings.Game.LockMouseWindow)
            {
                GrabWindowMouseFocus();
            }
            else
            {
                ReleaseWindowMouseFocus();
            }

            if (windowMode == WindowMode.Fullscreen)
            {
                SDL.SDL_SetWindowFullscreen(window, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN);
            }
            else if (windowMode == WindowMode.PseudoFullscreen)
            {
                // Work around a visual glitch in OSX: the window is offset
                // partially offscreen if the dock is at the left of the screen
                if (Platform.CurrentPlatform == PlatformType.OSX)
                {
                    SDL.SDL_SetWindowPosition(window, 0, 0);
                }

                SDL.SDL_SetWindowFullscreen(window, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP);
                SDL.SDL_SetHint(SDL.SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
            }

            context = SDL.SDL_GL_CreateContext(window);
            SDL.SDL_GL_MakeCurrent(window, context);
            GL.LoadAll();
            ErrorHandler.CheckGlVersion();
            ErrorHandler.CheckGlError();

            if (SDL.SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object") == SDL.SDL_bool.SDL_FALSE)
            {
                ErrorHandler.WriteGraphicsLog("OpenRA requires the OpenGL extension GL_EXT_framebuffer_object.\n"
                                              + "Please try updating your GPU driver to the latest version provided by the manufacturer.");
                throw new InvalidProgramException("Missing OpenGL extension GL_EXT_framebuffer_object. See graphics.log for details.");
            }

            GL.EnableClientState(ArrayCap.VertexArray);
            ErrorHandler.CheckGlError();
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            ErrorHandler.CheckGlError();

            SDL.SDL_SetModState(0);
            input = new Sdl2Input();
        }
Esempio n. 4
0
        public Sdl2GraphicsDevice(Size windowSize, WindowMode windowMode)
        {
            size = windowSize;

            SDL.SDL_Init(SDL.SDL_INIT_NOPARACHUTE | SDL.SDL_INIT_VIDEO);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
            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, 0);

            var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;
            if (windowMode == WindowMode.Fullscreen)
                windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
            else if (windowMode == WindowMode.PseudoFullscreen)
            {
                windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
                Environment.SetEnvironmentVariable("SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", "0");
            }

            SDL.SDL_DisplayMode display;
            SDL.SDL_GetCurrentDisplayMode(0, out display);

            Console.WriteLine("Desktop resolution: {0}x{1}", display.w, display.h);
            if (size.Width == 0 && size.Height == 0)
            {
                Console.WriteLine("No custom resolution provided, using desktop resolution");
                size = new Size(display.w, display.h);
            }

            Console.WriteLine("Using resolution: {0}x{1}", size.Width, size.Height);

            window = SDL.SDL_CreateWindow("OpenRA", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, size.Width, size.Height, windowFlags);

            SDL.SDL_ShowCursor(0);
            SDL.SDL_GL_CreateContext(window);
            ErrorHandler.CheckGlError();

            var extensions = Gl.glGetString(Gl.GL_EXTENSIONS);
            if (extensions == null)
                Console.WriteLine("Failed to fetch GL_EXTENSIONS, this is bad.");

            var missingExtensions = requiredExtensions.Where(r => !extensions.Contains(r)).ToArray();
            if (missingExtensions.Any())
            {
                ErrorHandler.WriteGraphicsLog("Unsupported GPU: Missing extensions: {0}".F(missingExtensions.JoinWith(",")));
                throw new InvalidProgramException("Unsupported GPU. See graphics.log for details.");
            }

            Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
            ErrorHandler.CheckGlError();
            Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
            ErrorHandler.CheckGlError();

            SDL.SDL_SetModState(0);
            input = new Sdl2Input();
        }