Exemple #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);
            GLFW.WindowHint(GLFW_Enum.MAXIMIZED, flags.HasFlag(WindowFlags.Maximized));

            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);
        }
Exemple #2
0
        protected override void ApplicationStarted()
        {
            if (GLFW.Init() == 0)
            {
                GLFW.GetError(out string error);
                throw new Exception($"GLFW Error: {error}");
            }

            // OpenGL Setup
            if (App.Graphics is IGraphicsOpenGL)
            {
                // macOS requires versions to be set to 3.2
                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    GLFW.WindowHint(GLFW_Enum.CONTEXT_VERSION_MAJOR, 3);
                    GLFW.WindowHint(GLFW_Enum.CONTEXT_VERSION_MINOR, 2);
                    GLFW.WindowHint(GLFW_Enum.OPENGL_PROFILE, 0x00032001);
                    GLFW.WindowHint(GLFW_Enum.OPENGL_FORWARD_COMPAT, true);
                }
            }
            else
            {
                GLFW.WindowHint(GLFW_Enum.CLIENT_API, (int)GLFW_Enum.NO_API);
            }

            // Various constant Window Hints
            GLFW.WindowHint(GLFW_Enum.DOUBLEBUFFER, true);
            GLFW.WindowHint(GLFW_Enum.DEPTH_BITS, 24);
            GLFW.WindowHint(GLFW_Enum.STENCIL_BITS, 8);

            // Monitors
            unsafe
            {
                var monitorPtrs = GLFW.GetMonitors(out int count);
                for (int i = 0; i < count; i++)
                {
                    monitors.Add(new GLFW_Monitor(monitorPtrs[i]));
                }
            }

            // Init Input
            input.Init();
        }