glfw

GLFW windowing and input library bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_glfw.cC FFI wrapper
c/kit_glfw.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/glfw.kitKit GLFW - Windowing and input library bindings
tests/glfw.test.kitTests for glfw

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-glfw.git

System Requirements

PlatformCommand
macOSbrew install glfw
Ubuntusudo apt install libglfw3-dev
Fedorasudo dnf install glfw-devel

Usage

import Kit.GLFW as Glfw

main = fn =>
  match Glfw.init
    | Ok _ ->
      println "GLFW initialized"

      # Create a hidden window
      Glfw.window-hint (Glfw.hint-visible) (Glfw.glfw-false)

      match Glfw.create-window 800 600 "Kit GLFW Example"
        | Ok win ->
          println ("Window: " ++ (show (Glfw.get-width win)) ++ "x" ++ (show (Glfw.get-height win)))
          println ("Framebuffer: " ++ (show (Glfw.get-framebuffer-width win)) ++ "x" ++ (show (Glfw.get-framebuffer-height win)))
          println ("Time: " ++ (show Glfw.get-time))
          Glfw.destroy-window win
        | Err e -> println ("Window error: " ++ e)

      Glfw.terminate
    | Err e -> println ("Init error: " ++ e)

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/glfw/, making it available for import as Kit.GLFW in other projects.

License

This package is released under the MIT License - see LICENSE for details.

GLFW is released under the zlib/libpng License.

Exported Functions & Types

key-escape

Escape key constant.

Int

key-enter

Enter/Return key constant.

Int

key-space

Space bar key constant.

Int

key-up

Up arrow key constant.

Int

key-down

Down arrow key constant.

Int

key-left

Left arrow key constant.

Int

key-right

Right arrow key constant.

Int

key-a

A key constant.

Int

key-w

W key constant.

Int

key-s

S key constant.

Int

key-d

D key constant.

Int

action-press

Key press action constant.

Int

action-release

Key release action constant.

Int

action-repeat

Key repeat action constant.

Int

mouse-left

Left mouse button constant.

Int

mouse-right

Right mouse button constant.

Int

mouse-middle

Middle mouse button constant.

Int

hint-resizable

Resizable window hint constant.

Int

hint-visible

Visible window hint constant.

Int

hint-decorated

Decorated window hint constant.

Int

hint-focused

Focused window hint constant.

Int

hint-floating

Floating window hint constant.

Int

hint-maximized

Maximized window hint constant.

Int

glfw-true

GLFW TRUE constant (for window hints).

Int

glfw-false

GLFW FALSE constant (for window hints).

Int

init

Initialize GLFW. Must be called before any other GLFW functions.

Returns:

Result Unit String

terminate

Terminate GLFW and release all resources.

Unit

create-window

Create a window with the given dimensions and title.

Parameters:

Returns:

Int -> Int -> String -> Result Ptr String

destroy-window

Destroy a window and its context.

Parameters:

    Ptr -> Unit

should-close?

Check if the window has been requested to close.

Parameters:

Returns:

Ptr -> Bool

set-should-close

Set whether the window should close.

Parameters:

    Ptr -> Bool -> Unit

get-width

Get the width of a window in screen coordinates.

Parameters:

Returns:

Ptr -> Int

get-height

Get the height of a window in screen coordinates.

Parameters:

Returns:

Ptr -> Int

set-title

Set the window title.

Parameters:

    Ptr -> String -> Unit

set-size

Set the window size.

Parameters:

    Ptr -> Int -> Int -> Unit

set-position

Set the window position.

Parameters:

    Ptr -> Int -> Int -> Unit

get-position-x

Get the X position of the window.

Parameters:

Returns:

Ptr -> Int

get-position-y

Get the Y position of the window.

Parameters:

Returns:

Ptr -> Int

get-framebuffer-width

Get the framebuffer width in pixels (may differ from window size on HiDPI).

Parameters:

Returns:

Ptr -> Int

get-framebuffer-height

Get the framebuffer height in pixels (may differ from window size on HiDPI).

Parameters:

Returns:

Ptr -> Int

make-context-current

Make the OpenGL context of the window current.

Parameters:

    Ptr -> Unit

swap-buffers

Swap the front and back buffers of the window.

Parameters:

    Ptr -> Unit

swap-interval

Set the swap interval (0 = no vsync, 1 = vsync).

Parameters:

    Int -> Unit

poll-events

Process all pending events.

Unit

wait-events

Wait until events are received, then process them.

Unit

wait-events-timeout

Wait for events with a timeout in seconds.

Parameters:

    Float -> Unit

get-key

Get the state of a keyboard key.

Parameters:

Returns:

Ptr -> Int -> Int

is-key-pressed?

Check if a key is currently pressed.

Parameters:

Returns:

Ptr -> Int -> Bool

get-mouse-button

Get the state of a mouse button.

Parameters:

Returns:

Ptr -> Int -> Int

get-cursor-x

Get the X position of the cursor.

Parameters:

Returns:

Ptr -> Float

get-cursor-y

Get the Y position of the cursor.

Parameters:

Returns:

Ptr -> Float

get-time

Get the time in seconds since GLFW was initialized.

Returns:

Float

set-time

Set the GLFW timer value.

Parameters:

    Float -> Unit

default-window-hints

Reset window hints to their defaults.

Unit

window-hint

Set a window hint before creating a window.

Parameters:

    Int -> Int -> Unit

version

Get the GLFW version string.

Returns:

String