コード例 #1
0
        public static void CaptureMouse(bool Capture)
        {
            Glfw.CursorMode M = Capture ? Glfw.CursorMode.Disabled : Glfw.CursorMode.Normal;

            if (LastCursorMode != M)
            {
                LastCursorMode = M;
                Glfw.SetInputMode(Window, Glfw.InputMode.Cursor, M);
            }
        }
コード例 #2
0
ファイル: Gamepad.cs プロジェクト: nsglover/Bronze
 static Gamepad()
 {
     Joystick.Connected += (joystick, connected) =>
     {
         if (Glfw.JoystickIsGamepad(joystick.Id) == Glfw.True)
         {
             Connected?.Invoke(new Gamepad(joystick.Id));
         }
     };
 }
コード例 #3
0
        protected override void UpdateGamePadStates()
        {
            axisValues = Glfw.GetJoystickAxes(GetJoystickByNumber());
            var buttons = Glfw.GetJoystickButtons(GetJoystickByNumber());

            if (buttons != null && buttons.Length >= 10)
            {
                UpdateAllButtons(buttons);
            }
        }
コード例 #4
0
        private void UpdateKeyState(Key key)
        {
            bool isKeyPressed = Glfw.GetKey(nativeWindow, ConvertToPencilKey(key));

            keyboardStates[(int)key] = keyboardStates[(int)key].UpdateOnNativePressing(isKeyPressed);
            if (keyboardStates[(int)key] == State.Pressing)
            {
                newlyPressedKeys.Add(key);
            }
        }
コード例 #5
0
 public virtual void SetFullscreen(Size setFullscreenViewportSize)
 {
     windowedSize = viewportSize;
     Glfw.DestroyWindow(nativeWindow);
     CreateWindow(setFullscreenViewportSize, true);
     if (FullscreenChanged != null)
     {
         FullscreenChanged(setFullscreenViewportSize, true);
     }
 }
コード例 #6
0
 private void SetupWindow()
 {
     int[] colorBits = GetColorBits();
     Glfw.WindowHint(WindowHint.RedBits, colorBits[0]);
     Glfw.WindowHint(WindowHint.GreenBits, colorBits[1]);
     Glfw.WindowHint(WindowHint.BlueBits, colorBits[2]);
     Glfw.WindowHint(WindowHint.AlphaBits, colorBits[3]);
     Glfw.WindowHint(WindowHint.DepthBits, settings.DepthBufferBits);
     Glfw.WindowHint(WindowHint.Samples, settings.AntiAliasingSamples);
 }
コード例 #7
0
        private void OpenWindow(bool startInFullscreen, int width, int height)
        {
            GlfwMonitorPtr monitor = startInFullscreen ? Glfw.GetPrimaryMonitor() : GlfwMonitorPtr.Null;

            SetupWindow();
            nativeWindow = Glfw.CreateWindow(width, height, "GLFW3", monitor, GlfwWindowPtr.Null);
            Glfw.MakeContextCurrent(nativeWindow);
            Glfw.SetWindowSizeCallback(nativeWindow, OnWindowResize);
            Glfw.SwapInterval(settings.UseVSync);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Zexyp/CrossEngine
 private static void PrepareContext()
 {
     // Set some common hints for the OpenGL profile creation
     Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGL);
     Glfw.WindowHint(Hint.ContextVersionMajor, 3);
     Glfw.WindowHint(Hint.ContextVersionMinor, 3);
     Glfw.WindowHint(Hint.OpenglProfile, Profile.Core);
     Glfw.WindowHint(Hint.Doublebuffer, true);
     Glfw.WindowHint(Hint.Decorated, true);
 }
コード例 #9
0
        private void CloseCallback(Window window)
        {
            var closing = new ClosingEventArgs();

            aggSystemWindow.OnClosing(closing);
            if (closing.Cancel)
            {
                Glfw.SetWindowShouldClose(glfwWindow, false);
            }
        }
コード例 #10
0
ファイル: Graphics.cs プロジェクト: SpydazWebAI/nes
        public void Initialise(int zoomOverride)
        {
            lock (RenderLockBlob)
            {
                GraphicsThread = Thread.CurrentThread;

                if (Glfw.glfwInit() != 1)
                {
                    throw new Exception("GLFW initialisation failed. No, I have no idea why either.");
                }

                Glfw.GLFWvidmode vidDesktop = new Glfw.GLFWvidmode(); // not necessary b/c struct but whatever, man!
                Glfw.glfwGetDesktopMode(out vidDesktop);

                if (zoomOverride == 0)
                {
                    int zoomLevel = 1;

                    while ((Width * (zoomLevel * 2)) <= vidDesktop.Width &&
                           (Height * (zoomLevel * 2)) <= vidDesktop.Height)
                    {
                        zoomLevel *= 2;
                    }

                    if (Glfw.glfwOpenWindow(zoomLevel * Width, zoomLevel * Height, 0, 0, 0, 8, 16, 0, Glfw.GLFW_WINDOW) != 1)
                    {
                        throw new Exception("Failed to create GLFW window, for whatever reason.");
                    }
                }
                else
                {
                    if (Glfw.glfwOpenWindow(zoomOverride * Width, zoomOverride * Height, 0, 0, 0, 8, 16, 0, Glfw.GLFW_WINDOW) != 1)
                    {
                        throw new Exception("Failed to create GLFW window, for whatever reason.");
                    }
                }

                windowCloseFunc = new Glfw.GLFWwindowclosefun(OnWindowClose);
                Glfw.glfwSetWindowCloseCallback(windowCloseFunc);

                NPOTAllowed = Gl.glGetString(Gl.GL_EXTENSIONS).ToLower().Split(' ')
                              .Contains("gl_arb_texture_non_power_of_two");
                // Future: Fallback to gl_*_texture_rectangle where possible?

                Gl.glMatrixMode(Gl.GL_PROJECTION);
                Gl.glLoadIdentity();
                //Glu.gluOrtho2D(0, Width, Height, 0);
                Gl.glOrtho(0, Width, Height, 0, -1000, 1000);

                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();

                Gl.glEnable(Gl.GL_BLEND);
            }
        }
コード例 #11
0
 static void key(GlfwWindowPtr window, Key key, int scanCode, KeyAction action, KeyModifiers mods)
 {
     if (key == Key.Escape && action == KeyAction.Press)
     {
         Glfw.SetWindowShouldClose(window, true);
     }
     if (key == Key.Space && action == KeyAction.Press)
     {
         debug = !debug;
     }
 }
コード例 #12
0
        /// <summary>
        /// Stops this renderer.
        /// </summary>
        public void Stop()
        {
            // Destroy client reference
            //
            ParentClient = null;
            FreeTypeService.Dispose();

            Glfw.Terminate();

            Closed?.Invoke(this, EventArgs.Empty);
        }
コード例 #13
0
 private void calculateAngleAroundPlayer()
 {
     if (Glfw.GetMouseButton(window, Glfw.MouseButton.Button2))
     {
         double xPos;
         double yPos;
         Glfw.GetCursorPos(window, out xPos, out yPos);
         float angleChange = (float)xPos * 0.004f;
         angleAroundPlayer -= angleChange;
     }
 }
コード例 #14
0
        public void Destroy()
        {
            // - Warn extern resource before destroying the window
            Invalidating?.Invoke(this, EventArgs.Empty);

            // - Destroy the window
            Glfw.DestroyWindow(GLFWHAndle);

            // - Set the pointer to null
            GLFWHAndle = Window.None;
        }
コード例 #15
0
        /// <summary>
        /// Bind this graphic context (for OpenGL or statefull libraries).
        /// </summary>
        public void BindContext()
        {
            // - If not initialized do nothing
            if (!IsValid)
            {
                throw new InvalidOperationException("Window not initialized");
            }

            // - Set the context on this thread
            Glfw.MakeContextCurrent(GLFWHAndle);
        }
コード例 #16
0
 public static void UseDefault(Window window, bool clear = false)
 {
     Gl.glBindFramebuffer(0);
     Glfw.GetWindowSize(window, out var width, out var height);
     Gl.glViewport(0, 0, width, height);
     if (clear)
     {
         DefaultClearOption.Clear();
     }
     Log.LogOnGlErr("[Framebuffer:UseDefault]");
 }
コード例 #17
0
ファイル: Joystick.cs プロジェクト: nsglover/Bronze
        static Joystick()
        {
            ContextManager.EnsureDefaultContext();

            for (int i = 0; i < MaxConnectedJoysticks; i++)
            {
                PrivateJoysticks.Add(new Joystick(i));
            }

            Glfw.SetJoystickCallback((joy, connectionEvent) => Connected?.Invoke(Joysticks[joy], connectionEvent == Glfw.Connected));
        }
コード例 #18
0
        /// <summary>
        /// Show the window
        /// </summary>
        public void Show()
        {
            // - If not initialized do nothing
            if (!IsValid)
            {
                throw new InvalidOperationException("Window not initialized");
            }

            // - Show the window
            Glfw.ShowWindow(GLFWHAndle);
        }
コード例 #19
0
        public Window(int width, int height, string name)
        {
            Width = width;
            Height = height;

            rescaleDelegate = Rescale;
            GlfwWindow = Glfw.CreateWindow(Width, Height, name);
            Glfw.Vidmode vidmode = Glfw.GetVideoMode(Glfw.GetPrimaryMonitor());
            Glfw.SetWindowPos(GlfwWindow, (vidmode.Width - Width) / 2, (vidmode.Height - Height) / 2);
            Glfw.SetWindowSizeCallback(GlfwWindow, rescaleDelegate);
        }
コード例 #20
0
ファイル: GLFunctionLoader.cs プロジェクト: Kakaff/Glue.Net
        /* These aren't used for anything, but might be in the future so i'm just going to comment them out.
         * [DllImport("opengl32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true),SuppressUnmanagedCodeSecurity]
         * internal static extern IntPtr wglGetProcAddress(string functionName);
         *
         * [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true), SuppressUnmanagedCodeSecurity]
         * internal static extern IntPtr GetProcAddress(string procname);
         */
        internal static T LoadGLFunction <T>(string name) where T : Delegate
        {
            IntPtr ptr = Glfw.GetProcAddress(name);

            if (ptr == IntPtr.Zero)
            {
                Console.WriteLine($"GLFunctionLoader Error: {name} not found");
                return(null);
            }
            return(Marshal.GetDelegateForFunctionPointer <T>(ptr));
        }
コード例 #21
0
ファイル: Particle.cs プロジェクト: ynzehettema/Infiltration
        public Particle(Vector2 position, Color4 color, float perpAngle, Random random)
        {
            this.position = position;
            this.color    = color;
            float spread = 45f;

            this.angle = (perpAngle - 180 - spread) + (float)random.NextDouble() * spread * 2;
            this.speed = 2f + (float)random.NextDouble() * 5f;
            size       = 1f + (float)random.NextDouble() * 2.5f;
            maxTime    = (float)Glfw.GetTime() * random.Next(10, 25);
        }
コード例 #22
0
ファイル: Game.cs プロジェクト: PlumpMath/LED_Engine
        static void OnMouseMove(GlfwWindowPtr window, double posx, double posy)
        {
            if (Settings.Window.IsFocused)
            {
                double CenterX = Settings.Window.X + Settings.Window.Width / 2;
                double CenterY = Settings.Window.Y + Settings.Window.Height / 2;

                MainCamera.AddRotation((float)(CenterX - posx), (float)(CenterY - posy));
                Glfw.SetCursorPos(window, CenterX, CenterY);
            }
        }
コード例 #23
0
        protected Camera(Window window)
        {
            _window = window;

            _winCenter = new ivec2();
            Glfw.GetWindowSize(_window, out _winCenter.x, out _winCenter.y);

            Glfw.SetCursorPosition(_window, _winCenter.x, _winCenter.y);

            setRotation(0, 0);
        }
コード例 #24
0
        static void WindowRefreshCallback(Glfw.Window window)
        {
            var slot = m_Slots[window];

            Log("{0} to {1} at {2}: Window refresh",
                m_Counter++, slot.Number, Glfw.GetTime());

            Glfw.MakeContextCurrent(window);
            Gl.Clear(ClearBufferMask.ColorBufferBit);
            Glfw.SwapBuffers(window);
        }
コード例 #25
0
ファイル: GlfwForms.cs プロジェクト: 52ChaseDream/PixelFarm
 public static void RunMainLoop()
 {
     while (!GlfwApp.ShouldClose())
     {
         //---------------
         //render phase and swap
         GlfwApp.UpdateWindowsFrame();
         /* Poll for and process events */
         Glfw.PollEvents();
     }
     Glfw.Terminate();
 }
コード例 #26
0
 void CheckNativeHandle()
 {
     if (_nativeGlFwWindowPtr.IsEmpty)
     {
         //create native glfw window
         this._nativeGlFwWindowPtr = Glfw.CreateWindow(this.Width,
                                                       this.Height,
                                                       this.Text,
                                                       new GlfwMonitorPtr(), //default monitor
                                                       new GlfwWindowPtr()); //default top window
     }
 }
コード例 #27
0
ファイル: GlRenderer.cs プロジェクト: rozniak/Junkbot
        /// <summary>
        /// Starts this renderer.
        /// </summary>
        /// <param name="gameInstance">
        /// A reference to the Junkbot game engine instance.
        /// </param>
        public void Start(JunkbotGame gameInstance)
        {
            Game = gameInstance;
            CurrentInputState = new InputEvents();

            // Setup GLFW parameters and create window
            //
            Glfw.Init();

            Glfw.SetErrorCallback(OnError);

            Glfw.WindowHint(WindowHint.ContextVersionMajor, 3);
            Glfw.WindowHint(WindowHint.ContextVersionMinor, 2);
            Glfw.WindowHint(WindowHint.OpenGLForwardCompat, 1);
            Glfw.WindowHint(WindowHint.OpenGLProfile, (int)OpenGLProfile.Core);

            WindowPtr = Glfw.CreateWindow(650, 420, "Junkbot (OpenGL 3.2)", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);

            IsOpen = true;

            Glfw.MakeContextCurrent(WindowPtr);

            // Set GL pixel storage parameter
            //
            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

            // Set up VAO
            //
            GlVaoId = GL.GenVertexArray();
            GL.BindVertexArray(GlVaoId);

            // Set up enabled features
            //
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // Set up viewport defaults
            //
            GL.ClearColor(0.39f, 0.58f, 0.93f, 1.0f); // Approx. cornflower blue
            GL.Viewport(0, 0, (int)JUNKBOT_VIEWPORT.X, (int)JUNKBOT_VIEWPORT.Y);

            // Set up input callbacks
            //
            Glfw.SetCharCallback(WindowPtr, OnChar);
            Glfw.SetCursorPosCallback(WindowPtr, OnCursorPos);
            Glfw.SetKeyCallback(WindowPtr, OnKey);
            Glfw.SetMouseButtonCallback(WindowPtr, OnMouseButton);
            Glfw.SetWindowSizeCallback(WindowPtr, OnWindowSize);

            // Now attach the game state event to update our strategies
            //
            Game.ChangeState += Game_ChangeState;
        }
コード例 #28
0
        static void DropCallback(Glfw.Window window, int count, string[] paths)
        {
            var slot = m_Slots[window];

            Log("{0} to {1} at {2}: Drop input",
                m_Counter++, slot.Number, Glfw.GetTime());

            for (int i = 0; i < paths.Length; i++)
            {
                Log("  {0}: \"{1}\"", i, paths[i]);
            }
        }
コード例 #29
0
        static void DrawJoystick(int index, int x, int y, int width, int height)
        {
            int axisHeight   = 3 * height / 4;
            int buttonHeight = height / 4;

            var axes = Glfw.GetJoystickAxes(m_Joysticks[index]);

            if (axes != null)
            {
                int axis_width = width / axes.Length;

                for (int i = 0; i < axes.Length; i++)
                {
                    float value = axes[i] / 2f + 0.5f;

                    Gl.Color3(0.3f, 0.3f, 0.3f);
                    Gl.Rect(x + i * axis_width,
                            y,
                            x + (i + 1) * axis_width,
                            y + axisHeight);

                    Gl.Color3(1f, 1f, 1f);
                    Gl.Rect(x + i * axis_width,
                            y + (int)(value * (axisHeight - 5)),
                            x + (i + 1) * axis_width,
                            y + 5 + (int)(value * (axisHeight - 5)));
                }
            }

            var buttons = Glfw.GetJoystickButtons(m_Joysticks[index]);

            if (buttons != null)
            {
                int button_width = width / buttons.Length;

                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i])
                    {
                        Gl.Color3(1f, 1f, 1f);
                    }
                    else
                    {
                        Gl.Color3(0.3f, 0.3f, 0.3f);
                    }

                    Gl.Rect(x + i * button_width,
                            y + axisHeight,
                            x + (i + 1) * button_width,
                            y + axisHeight + buttonHeight);
                }
            }
        }
コード例 #30
0
        static void FindJoysticks()
        {
            for (int i = (int)Glfw.Joystick.Joystick1; i <= (int)Glfw.Joystick.JoystickLast; i++)
            {
                var joy = (Glfw.Joystick)i;

                if (Glfw.JoystickPresent(joy))
                {
                    JoystickCallback(joy, Glfw.ConnectionEvent.Connected);
                }
            }
        }