Sign in

    glfw

    GLFW MoonBit bindings (native FFI + C stub)

    glfw
    native
    ffi
    window
    input
    Download zip
    Author
    Version
    0.2.3
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    2K

    No dependencies

    #mizchi/glfw

    GLFW bindings for MoonBit (native target only).

    Provides window management, keyboard/mouse/touch/gamepad input, fullscreen control, and cursor handling via C FFI.

    #Install

    moon add mizchi/glfw

    Requires GLFW installed on the system:

    # macOS brew install glfw # Windows (vcpkg) vcpkg install glfw3 # Linux (apt) sudo apt install libglfw3-dev

    Consumer projects need -lglfw in their cc-link-flags (link flags do not propagate through dependencies).

    #Usage

    fn main {
    if @glfw.glfw_init() {
    let window = @glfw.create_window(800, 600, "Hello")
    while not(@glfw.window_should_close(window)) {
    @glfw.poll_events()
    // render...
    }
    @glfw.destroy_window(window)
    @glfw.terminate()
    }
    }

    #API

    #Window

    FunctionDescription
    glfw_init() -> BoolInitialize GLFW
    terminate()Terminate GLFW
    create_window(width, height, title) -> GLFWwindowCreate window (NO_API hint for WebGPU)
    destroy_window(window)Destroy window
    window_should_close(window) -> BoolCheck close flag
    set_window_should_close(window, value)Set close flag
    get_window_size(window) -> WindowSizeGet window size
    get_window_width(window) -> IntGet window width
    get_window_height(window) -> IntGet window height
    get_framebuffer_size(window) -> WindowSizeGet framebuffer size (Retina)
    get_window_content_scale(window) -> DoubleGet DPI scale factor
    set_fullscreen(window, enabled) -> BoolToggle fullscreen
    is_fullscreen(window) -> BoolCheck fullscreen state
    request_window_attention(window)Flash taskbar/dock
    swap_buffers(window)Swap front/back buffers
    set_swap_interval(enabled)Enable/disable vsync
    poll_events()Poll input events

    #Input

    FunctionDescription
    get_cursor_x(window) -> DoubleCursor X position
    get_cursor_y(window) -> DoubleCursor Y position
    set_cursor_mode(window, mode) -> IntSet cursor mode (0=normal, 1=hidden, 2=disabled)
    get_cursor_mode(window) -> IntGet cursor mode
    take_scroll_x(window) -> DoubleConsume scroll X delta
    take_scroll_y(window) -> DoubleConsume scroll Y delta
    pressed_key_count(window) -> IntNumber of pressed keys
    pressed_key_at(window, index) -> IntGLFW key code at index
    pressed_mouse_button_count(window) -> IntNumber of pressed mouse buttons
    pressed_mouse_button_at(window, index) -> IntMouse button at index
    touch_count(window) -> IntNumber of active touches (macOS trackpad)
    touch_id_at(window, index) -> IntTouch ID at index
    touch_x_at(window, index) -> DoubleTouch X at index
    touch_y_at(window, index) -> DoubleTouch Y at index
    touch_type_at(window, index) -> IntTouch type (0=direct, 1=indirect)
    gamepad_count() -> IntNumber of connected gamepads
    gamepad_id_at(index) -> IntGamepad joystick ID
    gamepad_axis_count(index) -> IntNumber of axes
    gamepad_axis_at(gamepad, axis) -> DoubleAxis value
    gamepad_pressed_button_count(index) -> IntNumber of pressed buttons
    gamepad_pressed_button_at(gamepad, button) -> IntButton at index

    #Platform Support

    PlatformStatus
    macOS (ARM/x86)Supported (touch input via Cocoa)
    WindowsBuilds on CI, not yet tested at runtime (touch input: no-op)
    LinuxBuilds on CI, not yet tested at runtime (touch input: no-op)

    #License

    Apache-2.0

    GLFWwindow

    type GLFWwindow

    WindowSize

    pub(all) struct WindowSize {
    width : Int
    height : Int
    }

    create_hidden_window

    fn create_hidden_window(width : Int, height : Int) -> GLFWwindow

    Create a hidden (invisible) GLFW window for headless rendering.

    create_window

    fn create_window(width : Int, height : Int, title : String) -> GLFWwindow

    destroy_window

    fn destroy_window(window : GLFWwindow) -> Unit

    gamepad_axis_at

    fn gamepad_axis_at(gamepad_index : Int, axis_index : Int) -> Double

    gamepad_axis_count

    fn gamepad_axis_count(index : Int) -> Int

    gamepad_count

    fn gamepad_count() -> Int

    gamepad_id_at

    fn gamepad_id_at(index : Int) -> Int

    gamepad_pressed_button_at

    fn gamepad_pressed_button_at(gamepad_index : Int, button_index : Int) -> Int

    gamepad_pressed_button_count

    fn gamepad_pressed_button_count(index : Int) -> Int

    get_cursor_mode

    fn get_cursor_mode(window : GLFWwindow) -> Int

    get_cursor_x

    fn get_cursor_x(window : GLFWwindow) -> Double

    get_cursor_y

    fn get_cursor_y(window : GLFWwindow) -> Double

    get_framebuffer_size

    fn get_framebuffer_size(window : GLFWwindow) -> WindowSize

    get_window_content_scale

    fn get_window_content_scale(window : GLFWwindow) -> Double

    get_window_height

    fn get_window_height(window : GLFWwindow) -> Int

    get_window_size

    fn get_window_size(window : GLFWwindow) -> WindowSize

    get_window_width

    fn get_window_width(window : GLFWwindow) -> Int

    glfw_init

    fn glfw_init() -> Bool

    is_fullscreen

    fn is_fullscreen(window : GLFWwindow) -> Bool

    poll_events

    fn poll_events() -> Unit

    pressed_key_at

    fn pressed_key_at(window : GLFWwindow, index : Int) -> Int

    pressed_key_count

    fn pressed_key_count(window : GLFWwindow) -> Int

    pressed_mouse_button_at

    fn pressed_mouse_button_at(window : GLFWwindow, index : Int) -> Int

    pressed_mouse_button_count

    fn pressed_mouse_button_count(window : GLFWwindow) -> Int

    request_window_attention

    fn request_window_attention(window : GLFWwindow) -> Unit

    set_cursor_mode

    fn set_cursor_mode(window : GLFWwindow, mode : Int) -> Int

    set_fullscreen

    fn set_fullscreen(window : GLFWwindow, enabled : Bool) -> Bool

    set_swap_interval

    fn set_swap_interval(enabled : Bool) -> Unit

    set_window_should_close

    fn set_window_should_close(window : GLFWwindow, value : Bool) -> Unit

    swap_buffers

    fn swap_buffers(window : GLFWwindow) -> Unit

    take_scroll_x

    fn take_scroll_x(window : GLFWwindow) -> Double

    take_scroll_y

    fn take_scroll_y(window : GLFWwindow) -> Double

    terminate

    fn terminate() -> Unit

    touch_count

    fn touch_count(window : GLFWwindow) -> Int

    touch_id_at

    fn touch_id_at(window : GLFWwindow, index : Int) -> Int

    touch_type_at

    fn touch_type_at(window : GLFWwindow, index : Int) -> Int

    touch_x_at

    fn touch_x_at(window : GLFWwindow, index : Int) -> Double

    touch_y_at

    fn touch_y_at(window : GLFWwindow, index : Int) -> Double

    window_should_close

    fn window_should_close(window : GLFWwindow) -> Bool

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io