Skip to content

glfw

FreeBodyEngine.core.window.glfw #

GLFW_CHARACTER_MAP = {Key.A: glfw.KEY_A, Key.B: glfw.KEY_B, Key.C: glfw.KEY_C, Key.D: glfw.KEY_D, Key.E: glfw.KEY_E, Key.F: glfw.KEY_F, Key.G: glfw.KEY_G, Key.H: glfw.KEY_H, Key.I: glfw.KEY_I, Key.J: glfw.KEY_J, Key.K: glfw.KEY_K, Key.L: glfw.KEY_L, Key.M: glfw.KEY_M, Key.N: glfw.KEY_N, Key.O: glfw.KEY_O, Key.P: glfw.KEY_P, Key.Q: glfw.KEY_Q, Key.R: glfw.KEY_R, Key.S: glfw.KEY_S, Key.T: glfw.KEY_T, Key.U: glfw.KEY_U, Key.V: glfw.KEY_V, Key.W: glfw.KEY_W, Key.X: glfw.KEY_X, Key.Y: glfw.KEY_Y, Key.Z: glfw.KEY_Z, Key.ONE: glfw.KEY_1, Key.TWO: glfw.KEY_2, Key.THREE: glfw.KEY_3, Key.FOUR: glfw.KEY_4, Key.FIVE: glfw.KEY_5, Key.SIX: glfw.KEY_6, Key.SEVEN: glfw.KEY_7, Key.EIGHT: glfw.KEY_8, Key.NINE: glfw.KEY_9, Key.ZERO: glfw.KEY_0, Key.MINUS: glfw.KEY_MINUS, Key.EQUAL: glfw.KEY_EQUAL, Key.LEFT_BRACKET: glfw.KEY_LEFT_BRACKET, Key.RIGHT_BRACKET: glfw.KEY_RIGHT_BRACKET, Key.BACKSLASH: glfw.KEY_BACKSLASH, Key.SEMICOLON: glfw.KEY_SEMICOLON, Key.APOSTROPHE: glfw.KEY_APOSTROPHE, Key.TILDE: glfw.KEY_GRAVE_ACCENT, Key.COMMA: glfw.KEY_COMMA, Key.PERIOD: glfw.KEY_PERIOD, Key.SLASH: glfw.KEY_SLASH, Key.SPACE: glfw.KEY_SPACE, Key.RETURN: glfw.KEY_ENTER, Key.BACKSPACE: glfw.KEY_BACKSPACE, Key.TAB: glfw.KEY_TAB, Key.ESCAPE: glfw.KEY_ESCAPE, Key.CAPS_LOCK: glfw.KEY_CAPS_LOCK, Key.L_CTRL: glfw.KEY_LEFT_CONTROL, Key.R_CTRL: glfw.KEY_RIGHT_CONTROL, Key.L_SHIFT: glfw.KEY_LEFT_SHIFT, Key.R_SHIFT: glfw.KEY_RIGHT_SHIFT, Key.L_ALT: glfw.KEY_LEFT_ALT, Key.R_ALT: glfw.KEY_RIGHT_ALT, Key.L_SUPER: glfw.KEY_LEFT_SUPER, Key.R_SUPER: glfw.KEY_RIGHT_SUPER, Key.INSERT: glfw.KEY_INSERT, Key.DELETE: glfw.KEY_DELETE, Key.HOME: glfw.KEY_HOME, Key.END: glfw.KEY_END, Key.PG_UP: glfw.KEY_PAGE_UP, Key.PG_DOWN: glfw.KEY_PAGE_DOWN, Key.UP: glfw.KEY_UP, Key.DOWN: glfw.KEY_DOWN, Key.LEFT: glfw.KEY_LEFT, Key.RIGHT: glfw.KEY_RIGHT, Key.F1: glfw.KEY_F1, Key.F2: glfw.KEY_F2, Key.F3: glfw.KEY_F3, Key.F4: glfw.KEY_F4, Key.F5: glfw.KEY_F5, Key.F6: glfw.KEY_F6, Key.F7: glfw.KEY_F7, Key.F8: glfw.KEY_F8, Key.F9: glfw.KEY_F9, Key.F10: glfw.KEY_F10, Key.F11: glfw.KEY_F11, Key.F12: glfw.KEY_F12, Key.F13: glfw.KEY_F13, Key.F14: glfw.KEY_F14, Key.F15: glfw.KEY_F15, Key.F16: glfw.KEY_F16, Key.F17: glfw.KEY_F17, Key.F18: glfw.KEY_F18, Key.F19: glfw.KEY_F19, Key.F20: glfw.KEY_F20, Key.F21: glfw.KEY_F21, Key.F22: glfw.KEY_F22, Key.F23: glfw.KEY_F23, Key.F24: glfw.KEY_F24, Key.NUMPAD_0: glfw.KEY_KP_0, Key.NUMPAD_1: glfw.KEY_KP_1, Key.NUMPAD_2: glfw.KEY_KP_2, Key.NUMPAD_3: glfw.KEY_KP_3, Key.NUMPAD_4: glfw.KEY_KP_4, Key.NUMPAD_5: glfw.KEY_KP_5, Key.NUMPAD_6: glfw.KEY_KP_6, Key.NUMPAD_7: glfw.KEY_KP_7, Key.NUMPAD_8: glfw.KEY_KP_8, Key.NUMPAD_9: glfw.KEY_KP_9, Key.NUMPAD_DECIMAL: glfw.KEY_KP_DECIMAL, Key.NUMPAD_DIVIDE: glfw.KEY_KP_DIVIDE, Key.NUMPAD_MULTIPLY: glfw.KEY_KP_MULTIPLY, Key.NUMPAD_SUBTRACT: glfw.KEY_KP_SUBTRACT, Key.NUMPAD_ADD: glfw.KEY_KP_ADD, Key.NUMPAD_ENTER: glfw.KEY_KP_ENTER} module-attribute #

GLFW_KEY_CALLBACK_TYPE_MAP = {glfw.PRESS: KeyCallbackType.PRESS, glfw.RELEASE: KeyCallbackType.RELEASE, glfw.REPEAT: KeyCallbackType.REPEAT} module-attribute #

glfw_mouse_button_map = {0: glfw.MOUSE_BUTTON_1, 1: glfw.MOUSE_BUTTON_2, 2: glfw.MOUSE_BUTTON_3, 3: glfw.MOUSE_BUTTON_4, 4: glfw.MOUSE_BUTTON_5, 5: glfw.MOUSE_BUTTON_6, 6: glfw.MOUSE_BUTTON_7, 7: glfw.MOUSE_BUTTON_8} module-attribute #

GLFWMouse(window) #

Bases: Mouse

Mouse implementation for the GLFW backend - polls button/position state from GLFW each frame.

Sets up per-button state tracking for window.

drag_threshold = 0.2 instance-attribute #

last_click_time = -500 instance-attribute #

scroll_delta = Vector(0, 0) instance-attribute #

window = window instance-attribute #

get_double_click(button) #

True on the frame button was pressed as part of a double-click.

get_down(button) #

True for as long as button is held down.

get_pressed(button) #

True on the frame button was pressed.

get_released(button) #

True on the frame button was released.

get_scroll_delta() #

How far the scroll wheel moved this frame, drained from the window's GLFW scroll callback each update().

hide_cursor() #

Hides the system cursor for this window.

set_cursor(shape='default') #

Sets the system cursor's shape via GLFW's standard-cursor API.

update() #

Polls GLFW's cursor/button state for this frame and updates screen and world-space position, click and drag state.

GLFWWindow(size, title, visible=True) #

Bases: Window

Window backend built on GLFW, the engine's cross-platform fallback.

Used whenever a native backend (X11/Wayland/Win32) isn't selected or available - GLFW handles window creation, the OpenGL context, and input polling itself, so this class is mostly a thin translation layer between GLFW's API and the engine's Window/Mouse contracts.

Initializes GLFW, creates the window and its OpenGL 4.3 core context, and makes it current.

visible=False (used by TestWindow, a thin subclass of this class) still creates a real, GL-rendering window - it just never maps it on screen, so an automated test session never pops up or steals focus.

framebuffer_size property #

The size, in pixels, of the GL framebuffer (may differ from size under display scaling).

position property writable #

The window's position on screen, in pixels, as (x, y).

size property writable #

The window's client area size, in pixels, as reported by GLFW.

window_type = 'glfw' instance-attribute #

close() #

Flags the GLFW window to close, destroys it, terminates GLFW, and emits QUIT.

create_mouse() #

Creates and returns this window's GLFWMouse.

draw() #

Swaps the GLFW window's front/back buffers to present the frame.

get_clipboard_text() #

GLFW abstracts clipboard access across X11/Wayland/Win32 itself - no protocol-specific work needed here, unlike the Wayland backend's own implementation. Returns None for an empty/non-text clipboard, same as GLFW's own glfwGetClipboardString (NULL on those).

is_ready() #

True as long as GLFW hasn't been told to close this window.

resize(window, width, height) #

GLFW window-size callback - fires WINDOW_RESIZE/FRAMEBUFFER_RESIZE for both programmatic and user-driven resizes.

set_clipboard_text(text) #

Same story as get_clipboard_text - GLFW already abstracts this across every backend it supports, no serial/data-source dance needed the way the Wayland backend's own implementation does.

set_title(new_title) #

Sets the OS-level window title.

update() #

Polls GLFW events for this frame and quits the engine once the window is told to close.

create_raw_offscreen_context() #

A bare GLFW-backed OpenGL context with no Window/Service wrapper around it at all - not a GLFWWindow, not registered as the 'window' service, no input/event pump, nothing. Used by graphics.ensure_gpu_context() for a genuinely headless compute-only session: "headless" means no window service running at all, not a window service that merely happens to be invisible.

Safe to call repeatedly - the same context is reused (and made current again, in case something else changed the current context on this thread since) rather than creating a new one each time.

destroy_raw_offscreen_context() #

Destroys the shared offscreen context created by create_raw_offscreen_context(), if one exists.