Example #1
0
        internal IntPtr CreateGlfwWindow(string title, int width, int height, WindowFlags flags)
        {
            GLFW.WindowHint(GLFW_Enum.VISIBLE, false);
            GLFW.WindowHint(GLFW_Enum.FOCUS_ON_SHOW, true);
            GLFW.WindowHint(GLFW_Enum.FOCUSED, true);
            GLFW.WindowHint(GLFW_Enum.TRANSPARENT_FRAMEBUFFER, flags.HasFlag(WindowFlags.Transparent));
            GLFW.WindowHint(GLFW_Enum.SCALE_TO_MONITOR, flags.HasFlag(WindowFlags.ScaleToMonitor));
            GLFW.WindowHint(GLFW_Enum.SAMPLES, flags.HasFlag(WindowFlags.MultiSampling) ? 4 : 0);

            IntPtr shared = IntPtr.Zero;

            if (App.Graphics is IGraphicsOpenGL && windowPointers.Count > 0)
            {
                shared = windowPointers[0];
            }

            var monitor = IntPtr.Zero;

            if (flags.HasFlag(WindowFlags.Fullscreen))
            {
                monitor = GLFW.GetPrimaryMonitor();
            }

            // create the GLFW Window and return thr pointer
            var ptr = GLFW.CreateWindow(width, height, title, monitor, shared);

            if (ptr == IntPtr.Zero)
            {
                GLFW.GetError(out string error);
                throw new Exception($"Unable to create a new Window: {error}");
            }
            windowPointers.Add(ptr);

            // create the Vulkan surface
            if (App.Graphics is IGraphicsVulkan vkGraphics)
            {
                var vkInstance = vkGraphics.GetVulkanInstancePointer();
                var result     = GLFW.CreateWindowSurface(vkInstance, ptr, IntPtr.Zero, out var surface);

                if (result != GLFW_VkResult.Success)
                {
                    throw new Exception($"Unable to create a Vulkan Surface, {result}");
                }

                vkSurfaces.Add(ptr, surface);
            }

            // show window
            if (!flags.HasFlag(WindowFlags.Hidden))
            {
                GLFW.ShowWindow(ptr);
            }

            return(ptr);
        }
Example #2
0
        protected override Window.Platform CreateWindow(string title, int width, int height, WindowFlags flags = WindowFlags.None)
        {
            if (Thread.CurrentThread.ManagedThreadId != MainThreadId)
            {
                throw new Exception("Creating a Window must be called from the Main Thread");
            }

            // create GLFW Window
            var ptr = CreateGlfwWindow(title, width, height, flags);

            // start listening for input on this Window
            input.StartListening(ptr);

            // Add the GL Context
            if (App.Graphics is IGraphicsOpenGL)
            {
                glContexts.Add(ptr, new GLFW_GLContext(ptr));
            }

            // create the actual Window object
            var window = new GLFW_Window(this, ptr, title, !flags.HasFlag(WindowFlags.Hidden));

            glfwWindows.Add(ptr, window);
            return(window);
        }
Example #3
0
        public Window(string title, int x, int y, int width, int height, WindowFlags flags)
        {
            if (String.IsNullOrEmpty(title))
            {
                title = "SharpDL Window";
            }

            Title  = title;
            X      = x;
            Y      = y;
            Width  = width;
            Height = height;

            List <WindowFlags> copyFlags = new List <WindowFlags>();

            foreach (WindowFlags flag in Enum.GetValues(typeof(WindowFlags)))
            {
                if (flags.HasFlag(flag))
                {
                    copyFlags.Add(flag);
                }
            }

            Flags = copyFlags;

            Handle = SDL.SDL_CreateWindow(this.Title, this.X, this.Y, this.Width, this.Height, (SDL.SDL_WindowFlags)flags);
            if (Handle == IntPtr.Zero)
            {
                throw new InvalidOperationException(String.Format("SDL_CreateWindow: {0}", SDL.SDL_GetError()));
            }
        }
Example #4
0
        internal Window(string title, int x, int y, int width, int height, WindowFlags flags, ILogger <Window> logger = null)
        {
            if (string.IsNullOrWhiteSpace(title))
            {
                title = "SharpDL Window";
            }

            if (width < 0)
            {
                width = 0;
            }

            if (height < 0)
            {
                height = 0;
            }

            this.logger = logger;

            Title  = title;
            X      = x;
            Y      = y;
            Width  = width;
            Height = height;

            List <WindowFlags> copyFlags = new List <WindowFlags>();

            foreach (WindowFlags flag in Enum.GetValues(typeof(WindowFlags)))
            {
                if (flags.HasFlag(flag))
                {
                    copyFlags.Add(flag);
                }
            }

            Flags = copyFlags;

            IntPtr unsafeHandle = SDL.SDL_CreateWindow(this.Title, this.X, this.Y, this.Width, this.Height, (SDL.SDL_WindowFlags)flags);

            if (unsafeHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException($"SDL_CreateWindow: {SDL.SDL_GetError()}");
            }
            safeHandle = new SafeWindowHandle(unsafeHandle);
        }
Example #5
0
        public Window(string title, int x, int y, int width, int height, WindowFlags flags)
        {
            if (String.IsNullOrEmpty(title))
            {
                title = "SharpDL Window";
            }

            Title = title;
            X = x;
            Y = y;
            Width = width;
            Height = height;

            List<WindowFlags> copyFlags = new List<WindowFlags>();
            foreach (WindowFlags flag in Enum.GetValues(typeof(WindowFlags)))
                if (flags.HasFlag(flag))
                    copyFlags.Add(flag);

            Flags = copyFlags;

            Handle = SDL.SDL_CreateWindow(this.Title, this.X, this.Y, this.Width, this.Height, (SDL.SDL_WindowFlags)flags);
            if (Handle == IntPtr.Zero)
                throw new Exception(String.Format("SDL_CreateWindow: {0}", SDL.SDL_GetError()));
        }