public void move(Glfw.Window window) { bool W = Glfw.GetKey(window, (int)Glfw.KeyCode.W); bool D = Glfw.GetKey(window, (int)Glfw.KeyCode.D); bool A = Glfw.GetKey(window, (int)Glfw.KeyCode.A); bool S = Glfw.GetKey(window, (int)Glfw.KeyCode.S); if (W) { positin.z -= 0.1f; } if (S) { positin.z += 0.1f; } if (D) { positin.x += 0.1f; } if (A) { positin.x -= 0.1f; } }
static void CloseWindow(Glfw.Window window) { double b = Glfw.GetTime(); Glfw.DestroyWindow(window); Log("Closing window took {0} seconds", Glfw.GetTime() - b); }
public void move(Glfw.Window window) { bool W = Glfw.GetKey(window, (int)Glfw.KeyCode.W); bool D = Glfw.GetKey(window, (int)Glfw.KeyCode.D); bool A = Glfw.GetKey(window, (int)Glfw.KeyCode.A); bool S = Glfw.GetKey(window, (int)Glfw.KeyCode.S); bool space = Glfw.GetKey(window, (int)Glfw.KeyCode.Space); bool c = Glfw.GetKey(window, (int)Glfw.KeyCode.C); if (W) { positin.z -= 0.6f; } if (S) { positin.z += 0.6f; } if (D) { positin.x += 0.6f; } if (A) { positin.x -= 0.6f; } if (space) { positin.y += 0.6f; } if (c) { positin.y -= 0.6f; } }
internal void Init() { Glfw.ConfigureNativesDirectory(GlfwLibraryPath); // Check glfw init Debug.Assert(() => Glfw.Init(), "Glfw Could not be initialised", LogLayer.Application, LogState.Error, () => { Environment.Exit(-1); }, "Glfw has been Initialised"); // Create window window = Glfw.CreateWindow(Width, Height, Name); Debug.Assert(() => window, "Window could not be created", LogLayer.Application, LogState.Error, () => { Glfw.Terminate(); Environment.Exit(-1); }, $"Window has been created {Width}x{Height}"); Glfw.SwapInterval(SwapInterval); Glfw.MakeContextCurrent(window); // Set character callback Glfw.SetCharCallback(window, new Glfw.CharFunc((w, code) => { })); }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state == Glfw.InputState.Press && key == Glfw.KeyCode.Escape) { Glfw.SetWindowShouldClose(window, true); } }
private void handleKeys(Glfw.Window window, Glfw.KeyCode key, int scan, Glfw.KeyAction action, Glfw.KeyMods mods) { if (key == Glfw.KeyCode.Left) { InputEvent(new InputEvent { FootSwitchEvent = new FootSwitchEvent { FootSwitch = FootSwitch.Left, Action = (FootSwitchAction)(int)action // conveniently, the enum values line up. } }); } else if (key == Glfw.KeyCode.Right) { InputEvent(new InputEvent { FootSwitchEvent = new FootSwitchEvent { FootSwitch = FootSwitch.Right, Action = (FootSwitchAction)(int)action // conveniently, the enum values line up. } }); } }
static void WindowSizeCallback(Glfw.Window window, int width, int height) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Window size: {3} {4}", m_Counter++, slot.Number, Glfw.GetTime(), width, height); }
static void CursorPositionCallback(Glfw.Window window, double x, double y) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Cursor position: {3} {4}", m_Counter++, slot.Number, Glfw.GetTime(), x, y); }
static void CursorEnterCallback(Glfw.Window window, bool entered) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Cursor {3} window", m_Counter++, slot.Number, Glfw.GetTime(), entered ? "entered" : "left"); }
static void WindowPosCallback(Glfw.Window window, int x, int y) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Window position: {3} {4}", m_Counter++, slot.Number, Glfw.GetTime(), x, y); }
public void Show() { _window = Glfw.CreateWindow(Width, Height, Title); if (_window == Glfw.Window.None) { throw new Exception(); } Glfw.SetWindowSizeCallback(_window, HandleSizeCallback); Glfw.SetWindowPosCallback(_window, HandlePosCallback); Glfw.SetWindowRefreshCallback(_window, HandleRefreshCallback); Glfw.SetWindowCloseCallback(_window, HandleCloseCallback); Glfw.SetWindowFocusCallback(_window, HandleFocusCallback); Glfw.SetWindowIconifyCallback(_window, HandleIconifyCallback); Glfw.SetFramebufferSizeCallback(_window, HandleFramebufferSizeCallback); Glfw.MakeContextCurrent(_window); //_context = NVG.CreateGL3Glew(3); //_context.CreateFont("sans-bold", "Roboto-Bold.ttf"); HandleRefreshCallback(_window); }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Space: { Glfw.GetWindowPos(window, out int xpos, out int ypos); Glfw.SetWindowPos(window, xpos, ypos); break; } case Glfw.KeyCode.Escape: { Glfw.SetWindowShouldClose(window, true); break; } default: break; } }
static void CharCallback(Glfw.Window window, uint codepoint) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Character 0x{3} ({4}) input", m_Counter++, slot.Number, Glfw.GetTime(), codepoint, GetCharacterString(codepoint)); }
void handleMousePos(Glfw.Window window, double x, double y) { float newX = ((float)x - 1.0f); float newY = (Height - 1.0f) - ((float)y - 1.0f); if (newX == cursorX && newY == cursorY) { return; } cursorX = newX; cursorY = newY; // NOTE: x,y can go outside window boundaries. if (cursorPressed) { InputEvent(new InputEvent { TouchEvent = new TouchEvent { Point = new Point(cursorX, cursorY), Action = TouchAction.Moved } }); } }
static void WindowIconifyCallback(Glfw.Window window, bool iconified) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Window was {3}", m_Counter++, slot.Number, Glfw.GetTime(), iconified ? "iconified" : "restored"); }
static void WindowFocusCallback(Glfw.Window window, bool focused) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Window {3}", m_Counter++, slot.Number, Glfw.GetTime(), focused ? "focused" : "defocused"); }
static void ScrollCallback(Glfw.Window window, double x, double y) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Scroll: {3} {4}", m_Counter++, slot.Number, Glfw.GetTime(), x, y); }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Escape: { Glfw.SetWindowShouldClose(window, true); break; } case Glfw.KeyCode.Space: { m_CurIconColor = (m_CurIconColor + 1) % 5; SetIcon(window, m_CurIconColor); break; } case Glfw.KeyCode.X: { Glfw.SetWindowIcon(window, null); break; } default: break; } }
static void SetGamma(Glfw.Window window, float gamma) { var monitor = Glfw.GetWindowMonitor(window); if (!monitor) { monitor = Glfw.GetPrimaryMonitor(); } if (gamma < 0f) { return; } // It is recommended to use gamma ramps of size 256, as that is the size supported by // all graphics cards on all platforms. const int kSize = 256; var ramp = new Glfw.GammaRamp { Red = new ushort[256], Green = new ushort[256], Blue = new ushort[256] }; for (int i = 0; i < kSize; i++) { float value; // Calculate intensity value = (float)i / (float)(kSize - 1); // Apply gamma curve value = (float)Math.Pow(value, 1f / gamma) * 65535f + 0.5f; // Clamp to value range if (value < 0f) { value = 0f; } else if (value > 65535f) { value = 65535f; } ramp.Red[i] = (ushort)value; ramp.Green[i] = (ushort)value; ramp.Blue[i] = (ushort)value; } m_GammaValue = gamma; Log("Set Gamma: {0}", m_GammaValue); Glfw.SetGammaRamp(monitor, ramp); var r = Glfw.GetGammaRamp(monitor); for (int i = 0; i < r.Size; i++) { Log("Ramp {0}: {1},{2},{3}", i, r.Red[i], r.Green[i], r.Blue[i]); } }
static void FramebufferSizeCallback(Glfw.Window window, int width, int height) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Framebuffer size: {3} {4}", m_Counter++, slot.Number, Glfw.GetTime(), width, height); Gl.Viewport(0, 0, width, height); }
static void CharModsCallback(Glfw.Window window, uint codepoint, Glfw.KeyMods mods) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Character 0x{3} ({4}) with modifiers ({5}) input", m_Counter++, slot.Number, Glfw.GetTime(), codepoint, GetCharacterString(codepoint), GetModsName(mods)); }
static void WindowCloseCallback(Glfw.Window window) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Window close", m_Counter++, slot.Number, Glfw.GetTime()); Glfw.SetWindowShouldClose(window, slot.Closeable); }
static void UpdateWindowTitle(Glfw.Window window) { string title = string.Format("Tearing detector (interval {0}{1}, {2} Hz)", swapInterval, (swapTear && swapInterval < 0) ? " (swap tear)" : "", frameRate); Glfw.SetWindowTitle(window, title); }
static void MouseButtonCallback(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Mouse button {3} ({4}) ({5}) was {6}", m_Counter++, slot.Number, Glfw.GetTime(), button, GetButtonName(button), GetModsName(mods), GetActioName(state)); }
private static void DropCallback(Glfw.Window window, int count, string[] paths) { var engineWindow = dictionary[window]; engineWindow.Dropped?.Invoke(engineWindow, new DroppedEventArgs() { Paths = paths }); }
static void CursorPositionCallback(Glfw.Window window, double x, double y) { Log("{0}: Cursor position: {1} {2} ({3} {4})", Glfw.GetTime(), x, y, x - cursorX, y - cursorY); cursorX = x; cursorY = y; }
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); }
private static void MouseMoveCallback(Glfw.Window window, double xpos, double ypos) { var engineWindow = dictionary[window]; engineWindow.MouseMoved?.Invoke(engineWindow, new MouseEventArgs() { X = xpos, Y = ypos }); }
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]); }
/// <summary> /// Starts the window thread. /// </summary> /// <param name="w">window</param> private void startWindowThread(Glfw.Window w) { while (!Glfw.WindowShouldClose(w)) { Gl.Clear(ClearBufferMask.ColorBufferBit); Glfw.SwapBuffers(w); Glfw.PollEvents(); } return; }