コード例 #1
0
        static Glfw.Window OpenWindow(int width, int height, Glfw.Monitor monitor)
        {
            double b;

            Glfw.Window window;

            b = Glfw.GetTime();

            window = Glfw.CreateWindow(width, height, "Window Re-opener", monitor, Glfw.Window.None);
            if (!window)
            {
                return(Glfw.Window.None);
            }

            Glfw.MakeContextCurrent(window);
            Glfw.SwapInterval(1);

            Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback);
            Glfw.SetWindowCloseCallback(window, WindowCloseCallback);
            Glfw.SetKeyCallback(window, KeyCallback);

            if (monitor)
            {
                Log("Opening full screen window on monitor {0} took {1} seconds",
                    Glfw.GetMonitorName(monitor),
                    Glfw.GetTime() - b);
            }
            else
            {
                Log("Opening regular window took {0} seconds",
                    Glfw.GetTime() - b);
            }

            return(window);
        }
コード例 #2
0
        protected override void UpdateDisplayMode()
        {
            Glfw.Monitor monitor = Glfw.GetWindowMonitor(_win);
            if (monitor.Ptr == IntPtr.Zero)
            {
                monitor = Glfw.GetPrimaryMonitor();
            }

            Glfw.GetMonitorPos(monitor, out int mX, out int mY);
            Glfw.VideoMode vidMode = Glfw.GetVideoMode(monitor);
            switch (DisplayMode)
            {
            case DisplayMode.Fullscreen:
                // This is not actually borderless windowed :(
                Glfw.SetWindowMonitor(_win, monitor, 0, 0, vidMode.Width, vidMode.Height, vidMode.RefreshRate);
                break;

            case DisplayMode.Windowed:
                Vector2 size = _windowModeSize ?? GetSize();
                _windowModeSize = null;
                Vector2 pos = new Vector2(mX, mY) + (new Vector2(vidMode.Width, vidMode.Height) / 2 - size / 2);
                Glfw.SetWindowMonitor(_win, new Glfw.Monitor(IntPtr.Zero), (int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y, Glfw.DontCare);
                break;
            }
        }
コード例 #3
0
        static void MonitorCallback(Glfw.Monitor monitor, Glfw.ConnectionEvent evt)
        {
            if (evt == Glfw.ConnectionEvent.Connected)
            {
                int x, y, widthMM, heightMM;
                var mode = Glfw.GetVideoMode(monitor);

                Glfw.GetMonitorPos(monitor, out x, out y);
                Glfw.GetMonitorPhysicalSize(monitor, out widthMM, out heightMM);

                Log("{0} at {1}: Monitor {2} ({3}x{4} at {5}x{6}, {7}x{8} mm) was connected",
                    m_Counter++,
                    Glfw.GetTime(),
                    Glfw.GetMonitorName(monitor),
                    mode.Width, mode.Height,
                    x, y,
                    widthMM, heightMM);
            }
            else if (evt == Glfw.ConnectionEvent.Disconnected)
            {
                Log("{0} at {1}: Monitor {2} was disconnected",
                    m_Counter++,
                    Glfw.GetTime(),
                    Glfw.GetMonitorName(monitor));
            }
        }
コード例 #4
0
        static void ListModes(Glfw.Monitor monitor)
        {
            int x, y, widthMM, heightMM;
            var mode  = Glfw.GetVideoMode(monitor);
            var modes = Glfw.GetVideoModes(monitor);

            Glfw.GetMonitorPos(monitor, out x, out y);
            Glfw.GetMonitorPhysicalSize(monitor, out widthMM, out heightMM);

            Log("Name: {0} ({1})",
                Glfw.GetMonitorName(monitor),
                Glfw.GetPrimaryMonitor() == monitor ? "primary" : "secondary");
            Log("Current mode: {0}", FormatMode(mode));
            Log("Virtual position: {0} {1}", x, y);

            Log("Physical size: {0} x {1} mm ({2} dpi)",
                widthMM, heightMM, mode.Width * 25.4f / widthMM);

            Log("Modes:");

            for (int i = 0; i < modes.Length; i++)
            {
                string currentMode = modes[i] == mode
                    ? "(current mode)"
                    : "";
                Log("{0}: {1} {2}", i, FormatMode(modes[i]), currentMode);
            }
        }
コード例 #5
0
        static Glfw.Window CreateWindow(Glfw.Monitor monitor)
        {
            int width, height;

            Glfw.Window window;

            if (monitor)
            {
                var mode = Glfw.GetVideoMode(monitor);

                Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate);
                Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits);
                Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits);
                Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits);

                width  = mode.Width;
                height = mode.Height;
            }
            else
            {
                width  = 640;
                height = 480;
            }

            window = Glfw.CreateWindow(width, height, "Iconify", monitor, Glfw.Window.None);
            if (!window)
            {
                Glfw.Terminate();
                System.Environment.Exit(1);
            }

            Glfw.MakeContextCurrent(window);

            return(window);
        }
コード例 #6
0
ファイル: GlfwWindow.cs プロジェクト: piRepos/pEngine-del
        private void Initialize()
        {
            if (Initialized)
                return;

            OperatingSystem OS = System.Environment.OSVersion;

            if (OS.Platform == PlatformID.Unix)
            {
                Glfw.WindowHint(Glfw.Hint.ContextVersionMajor, 3);
                Glfw.WindowHint(Glfw.Hint.ContextVersionMinor, 2);

                Glfw.WindowHint(Glfw.Hint.OpenglForwardCompat, 1);
                Glfw.WindowHint(Glfw.Hint.OpenglProfile, Glfw.OpenGLProfile.Core);
            }

            Glfw.WindowHint(Glfw.Hint.Samples, 4);
            Glfw.WindowHint(Glfw.Hint.Visible, false);
            Glfw.WindowHint((Glfw.Hint)Glfw.WindowAttrib.Resizable, true);

			GlfwMonitor primaryMonitor = (Monitor ?? Environment.Platform.MainMonitor) as GlfwMonitor;

			Glfw.Monitor monitor = Fullscreen ?	primaryMonitor.Handle : Glfw.Monitor.None;
            Glfw.Window Shared = SharedContext?.Handle ?? Glfw.Window.None;

			Handle = Glfw.CreateWindow(Size.Width, Size.Height, Title, monitor, Shared);

            Glfw.MakeContextCurrent(Handle);

			// - Screen center
			Position = (primaryMonitor.CurrentResolution.ResolutionSize - Size) / 2;

            Initialized = true;

            InitializePositionEvents();
			// InitializeDragDrop();

            Glfw.MakeContextCurrent(Glfw.Window.None);
        }
コード例 #7
0
ファイル: Window.cs プロジェクト: blackout1471/BrokenEngine
        /// <summary>
        /// Initialises the Glfw library and creates a window
        /// </summary>
        internal void Init()
        {
            // Get the specified Glfw.dll's directory
            Glfw.ConfigureNativesDirectory("..//..//Vendor/");

            // Init library
            if (!Glfw.Init())
            {
                Debug.Log("Could not initialise Glfw", Debug.DebugLayer.Application, Debug.DebugLevel.Error);
            }

            // Get monitor settings
            monitor = Glfw.GetPrimaryMonitor();

            // Create window
            window = Glfw.CreateWindow(width, height, title, Glfw.Monitor.None, Glfw.Window.None);
            if (!window)
            {
                Debug.Log("Could not create window", Debug.DebugLayer.Application, Debug.DebugLevel.Error);
            }

            // Make the current window the context
            Glfw.MakeContextCurrent(window);

            // Let glfw swap the buffers as fast as possible - 0 for fast 1 - for v sync
            Glfw.SwapInterval(0);

            // Set callbacks
            keyboardDel    = KeyboardCallBack;
            mouseButtonDel = MouseButtonCallBack;
            cursorPosDel   = CursorPosCallBack;

            Glfw.SetKeyCallback(window, keyboardDel);
            Glfw.SetMouseButtonCallback(window, mouseButtonDel);
            Glfw.SetCursorPosCallback(window, cursorPosDel);


            Debug.Log("Window Created size " + width + "x" + height, Debug.DebugLayer.Application, Debug.DebugLevel.Information);
        }
コード例 #8
0
ファイル: GlfwMonitor.cs プロジェクト: piRepos/pEngine-del
        private GlfwMonitor(Glfw.Monitor handle)
        {
            Handle = handle;
            int i = 0;

            // - Name set
            Name = Glfw.GetMonitorName(handle);

            // - Position set
            Vector2i position;

            Glfw.GetMonitorPos(handle, out position.X, out position.Y);
            Position = position;

            // - Supported resolutions
            Glfw.VideoMode[] modes   = Glfw.GetVideoModes(handle);
            Glfw.VideoMode   current = Glfw.GetVideoMode(handle);
            supportedResolutions = new Resolution[modes.Length];
            foreach (Glfw.VideoMode mode in modes)
            {
                Resolution r = new Resolution
                {
                    ResolutionSize = new Vector2i(mode.Width, mode.Height),
                    RefreshRate    = mode.RefreshRate,
                    RedBits        = mode.RedBits,
                    BlueBits       = mode.BlueBits,
                    GreenBits      = mode.GreenBits
                };

                supportedResolutions[i++] = r;

                if (current == mode)
                {
                    CurrentResolution = r;
                }
            }
        }
コード例 #9
0
ファイル: TestGammaRamp.cs プロジェクト: masums/NetCoreGLFW
        public void Main(string[] args)
        {
            Init();

            int width, height;

            Glfw.Window  window;
            Glfw.Monitor monitor = Glfw.Monitor.None;

            var options = new Options();

            if (Parser.Default.ParseArguments(args, options))
            {
                if (options.Fullscreen)
                {
                    monitor = Glfw.GetPrimaryMonitor();
                }
            }

            if (!Glfw.Init())
            {
                Environment.Exit(1);
            }

            if (monitor)
            {
                var mode = Glfw.GetVideoMode(monitor);

                Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate);
                Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits);
                Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits);
                Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits);

                width  = mode.Width;
                height = mode.Height;
            }
            else
            {
                width  = 200;
                height = 200;
            }

            window = Glfw.CreateWindow(width, height, "Gamma Test", monitor, Glfw.Window.None);
            if (!window)
            {
                Glfw.Terminate();
                Environment.Exit(1);
            }

            SetGamma(window, 1f);

            Glfw.MakeContextCurrent(window);
            Glfw.SwapInterval(1);

            Glfw.SetKeyCallback(window, KeyCallback);
            Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback);

            Gl.MatrixMode(MatrixMode.Projection);
            //Gl.Ortho(-1f, 1f, -1f, 1f, -1f, 1f);
            Gl.MatrixMode(MatrixMode.Modelview);

            Gl.ClearColor(0.5f, 0.5f, 0.5f, 0);

            while (!Glfw.WindowShouldClose(window))
            {
                Gl.Clear(ClearBufferMask.ColorBufferBit);

                Gl.Color3(0.8f, 0.2f, 0.4f);
                Gl.Rect(-0.5f, -0.5f, 0.5f, 0.5f);

                Glfw.SwapBuffers(window);
                Glfw.WaitEvents();
            }

            Glfw.Terminate();
        }
コード例 #10
0
        static void TestModes(Glfw.Monitor monitor)
        {
            Glfw.Window window;
            var         modes = Glfw.GetVideoModes(monitor);

            for (int i = 0; i < modes.Length; i++)
            {
                var            mode = modes[i];
                Glfw.VideoMode current;

                Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits);
                Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits);
                Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits);
                Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate);

                Log("Testing mode {0} on monitor {1}: {2}", i, Glfw.GetMonitorName(monitor), FormatMode(mode));

                window = Glfw.CreateWindow(mode.Width, mode.Height,
                                           "Video Mode Test",
                                           Glfw.GetPrimaryMonitor(),
                                           Glfw.Window.None);
                if (!window)
                {
                    Log("Failed to enter mode {0}: {1}", i, FormatMode(mode));
                    continue;
                }

                Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback);
                Glfw.SetKeyCallback(window, KeyCallback);

                Glfw.MakeContextCurrent(window);
                Glfw.SwapInterval(1);

                Glfw.SetTime(0.0);

                while (Glfw.GetTime() < 5.0)
                {
                    Gl.Clear(ClearBufferMask.ColorBufferBit);
                    Glfw.SwapBuffers(window);
                    Glfw.PollEvents();

                    if (Glfw.WindowShouldClose(window))
                    {
                        Log("User terminated program");

                        Glfw.Terminate();
                        Environment.Exit(0);
                    }
                }

                Gl.Get(GetPName.RedBits, out current.RedBits);
                Gl.Get(GetPName.GreenBits, out current.GreenBits);
                Gl.Get(GetPName.BlueBits, out current.BlueBits);

                Glfw.GetWindowSize(window, out current.Width, out current.Height);

                if (current.RedBits != mode.RedBits ||
                    current.GreenBits != mode.GreenBits ||
                    current.BlueBits != mode.BlueBits)
                {
                    Log("*** Color bit mismatch: ({0} {1} {2}) instead of ({3} {4} {5})\n",
                        current.RedBits, current.GreenBits, current.BlueBits,
                        mode.RedBits, mode.GreenBits, mode.BlueBits);
                }

                if (current.Width != mode.Width || current.Height != mode.Height)
                {
                    Log("*** Size mismatch: %ix%i instead of %ix%i\n",
                        current.Width, current.Height,
                        mode.Width, mode.Height);
                }

                Log("Closing window");

                Glfw.DestroyWindow(window);
                Glfw.PollEvents();
            }
        }
コード例 #11
0
        public GlfwPlatform(int width, int height, bool fullscreen = false)
        {
            midi = new MidiConsoleOut();

            // Handle Glfw errors:
            Glfw.SetErrorCallback((code, desc) => throw new Exception(String.Format("GLFW error code {0}: {1}", code, desc)));

            Debug.WriteLine("glfw.Init()");
            Glfw.Init();

            // Disable window resizing
            Glfw.WindowHint(Glfw.Hint.Resizable, false);
            // Enable multi-sampling
            Glfw.WindowHint(Glfw.Hint.Samples, 8);

            Glfw.Monitor monitor = fullscreen ? Glfw.GetPrimaryMonitor() : Glfw.Monitor.None;

            Debug.WriteLine("window = glfw.CreateWindow()");
            window = Glfw.CreateWindow(
                width,
                height,
                "e-sharp-minor",
                monitor,
                Glfw.Window.None
                );

            // Fetch the real window size:
            Glfw.GetWindowSize(window, out width, out height);

            // Window dimensions (aspect ratio) in VG coordinate space (non-retina):
            this.Width  = width;
            this.Height = height;

            // Get the real framebuffer size for OpenGL pixels; should work with Retina:
            int fbWidth, fbHeight;

            Glfw.GetFramebufferSize(window, out fbWidth, out fbHeight);

            // These are needed for vgClear since it works in framebuffer pixels.
            FramebufferWidth  = fbWidth;
            FramebufferHeight = fbHeight;

            Debug.WriteLine("glfw.MakeContextCurrent(window)");
            Glfw.MakeContextCurrent(window);

            // create an OpenVG context
            Debug.WriteLine("vgContext = vgPrivContextCreateAM(0)");
            vgContext = vgPrivContextCreateAM(IntPtr.Zero);

            // create a drawing surface (sRGBA premultiplied color space)
            //vgSurface = vgPrivSurfaceCreateAM(fbWidth, fbHeight, 0, 1, 1);
            vgSurface = vgPrivSurfaceCreateAM(fbWidth, fbHeight, 0, 1, 0);

            // bind context and surface
            vgPrivMakeCurrentAM(vgContext, vgSurface);

            // Create OpenVGContext:
            vg = new OpenVGContext();

            // Apply scale for retina display:
            vg.Seti(ParamType.VG_MATRIX_MODE, (int)MatrixMode.VG_MATRIX_PATH_USER_TO_SURFACE);
            vg.LoadIdentity();
            vg.Scale((float)fbWidth / (float)width, (float)fbHeight / (float)height);
            vg.Translate(0.5f, 0.5f);

            vg.Seti(ParamType.VG_MATRIX_MODE, (int)MatrixMode.VG_MATRIX_GLYPH_USER_TO_SURFACE);
            vg.LoadIdentity();
            vg.Scale((float)fbWidth / (float)width, (float)fbHeight / (float)height);
            vg.Translate(0.5f, 0.5f);

            vg.Seti(ParamType.VG_MATRIX_MODE, (int)MatrixMode.VG_MATRIX_PATH_USER_TO_SURFACE);

            // Disable vsync and show frame immediately after render:
            Glfw.SwapInterval(0);

            Debug.WriteLine("glfw.ShowWindow(window)");
            Glfw.ShowWindow(window);

            Glfw.SetKeyCallback(window, handleKeys);
            Glfw.SetMouseButtonCallback(window, handleMouseButton);
            Glfw.SetCursorPosCallback(window, handleMousePos);
        }