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); } }
static Gamepad() { Joystick.Connected += (joystick, connected) => { if (Glfw.JoystickIsGamepad(joystick.Id) == Glfw.True) { Connected?.Invoke(new Gamepad(joystick.Id)); } }; }
protected override void UpdateGamePadStates() { axisValues = Glfw.GetJoystickAxes(GetJoystickByNumber()); var buttons = Glfw.GetJoystickButtons(GetJoystickByNumber()); if (buttons != null && buttons.Length >= 10) { UpdateAllButtons(buttons); } }
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); } }
public virtual void SetFullscreen(Size setFullscreenViewportSize) { windowedSize = viewportSize; Glfw.DestroyWindow(nativeWindow); CreateWindow(setFullscreenViewportSize, true); if (FullscreenChanged != null) { FullscreenChanged(setFullscreenViewportSize, true); } }
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); }
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); }
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); }
private void CloseCallback(Window window) { var closing = new ClosingEventArgs(); aggSystemWindow.OnClosing(closing); if (closing.Cancel) { Glfw.SetWindowShouldClose(glfwWindow, false); } }
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); } }
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; } }
/// <summary> /// Stops this renderer. /// </summary> public void Stop() { // Destroy client reference // ParentClient = null; FreeTypeService.Dispose(); Glfw.Terminate(); Closed?.Invoke(this, EventArgs.Empty); }
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; } }
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; }
/// <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); }
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]"); }
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)); }
/// <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); }
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); }
/* 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)); }
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); }
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); } }
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); }
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); }
public static void RunMainLoop() { while (!GlfwApp.ShouldClose()) { //--------------- //render phase and swap GlfwApp.UpdateWindowsFrame(); /* Poll for and process events */ Glfw.PollEvents(); } Glfw.Terminate(); }
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 } }
/// <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; }
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]); } }
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); } } }
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); } } }