chez-libs

(system glfw)
Login

GLFW Bindings

Synopsis

(import (system glfw))

Bindings to the GLFW library.

Conditions

condition: &glfw

procedure: (glfw-condition? any)

procedure: (make-glfw-condition message code)

procedure: (glfw-condition-code condition)

The &glfw condition type is derived from &message and stores an error code together with a human-readable message.

parameter: current-glfw-condition

The binding automatically registers a GLFW error callback that stores the last encountered error in this parameter as a &glfw condition.

Initialization

procedure: (begin-glfw)

Initializes the GLFW library. This procedure is implicitly called when the binding library body is executed and only has to be called manually if the library is later terminated and needs to be initialized again. However, calling the procedure multiple times is harmless.

procedure: (end-glfw)

Terminates the GLFW library and destroys all windows and cursors.

Monitors

procedure: (monitor? any)

Checks whether the given object is a GLFW monitor.

procedure: (primary-monitor)

Returns the primary monitor.

procedure: (list-monitors)

Returns a list of all currently attached monitors.

procedure: (monitor-name monitor)

Retrieves the name of the given monitor.

procedure: (monitor-position monitor)

Retrieves the horizontal and vertical position of the monitor's upper left corner in the virtual screen coordinate space.

procedure: (monitor-size monitor)

Retrieves the horizontal and vertical size of the monitor in virtual screen coordinates.

procedure: (monitor-size/mm monitor)

Retrieves the horizontal and vertical physical size of the monitor in millimeters.

Video Modes

record: video-mode

procedure: (video-mode? any)

procedure: (make-video-mode width height red-bits green-bits blue-bits refresh-rate)

procedure: (video-mode-width mode)

procedure: (video-mode-height mode)

procedure: (video-mode-red-bits mode)

procedure: (video-mode-green-bits mode)

procedure: (video-mode-blue-bits mode)

procedure: (video-mode-refresh-rate mode)

A record type representing a video mode. Instances are serializable.

procedure: (monitor-video-mode monitor)

Retrieves the current video mode of the given monitor.

Window Hints

record: window-hints

procedure: (window-hints? any)

procedure: (make-window-hints arg ...)

procedure: (window-hints-alpha-bits hints)

procedure: (window-hints-depth-bits hints)

procedure: (window-hints-stencil-bits hints)

procedure: (window-hints-samples hints)

procedure: (window-hints-stereo? hints)

procedure: (window-hints-double-buffer? hints)

procedure: (window-hints-context-api hints)

procedure: (window-hints-context-version hints)

procedure: (window-hints-resizable? hints)

procedure: (window-hints-visible? hints)

procedure: (window-hints-decorated? hints)

procedure: (window-hints-focused? hints)

procedure: (window-hints-auto-iconify? hints)

procedure: (window-hints-floating? hints)

Window hints are represented as records extending video modes. Instances are serializable.

Instances may be constructed from any combination of monitor handles, video modes, existing window hints or field name symbols followed by values. Later constructor arguments override the values of earlier ones. The value #f by itself is ignored in the argument list.

parameter: current-window-hints

The window hints to be used in the construction of new windows are stored in a parameter. The parameter may be set to a monitor, video mode or window hints instance. When queried, the parameter always returns a window hints instance. When the parameter is set, the appropriate native GLFW window hints are also set. When the parameter is set to #f, the native window hints are reset to their default values.

Windows

procedure: (window? any)

Checks whether the given object is a GLFW window.

procedure: (make-window proc title width height monitor share)

procedure: (make-window proc title width height monitor)

procedure: (make-window proc title width height)

procedure: (make-window proc title monitor)

procedure: (make-window proc title)

Creates a new window. The given procedure is called to handle events (see below under "Events") and is passed to lock-object before it is stored in the native window.

If the width or height are not given or #f, their values are taken from the current window hints.

If only a monitor is given instead of width and height, the window hints are adapted for a fullscreen window using the monitor's current video mode. The window hints are restored to their previous state afterwards.

procedure: (destroy-window window unlock?)

procedure: (destroy-window window)

Destroys the given window. Iff the unlock? argument is given and not #f, the callback procedure of the window is passed to unlock-object.

procedure: (window-monitor window)

Retrieves the monitor that currently displays the given window.

procedure: (window-context-api window)

Retrieves the supported client API of the window's graphics context. The result may differ from the API specified in the window hints, but only if it subsumes the API specified in the window hints.

procedure: (window-context-version window)

Retrieves the version of the client API supported by the window's graphics context as a pair of two integers.

procedure: (window-title-set! window string)

Changes the title of a window.

procedure: (window-position window)

procedure: (window-position-set! window x y)

Access the horizontal and vertical position of the window's client area in the virtual screen coordinate space.

procedure: (window-size window)

procedure: (window-size-set! window x y)

Access the horizontal and vertical size of the window's client area in virtual screen coordinates.

procedure: (window-framebuffer-size window)

Retrieves the horizontal and vertical size of the window's framebuffer in pixels.

procedure: (window-frame-size window)

Retrieves the left, top, right and bottom window decoration sizes in virtual screen coordinates.

procedure: (window-should-close? window)

procedure: (window-should-close-set! window v)

Access the window close flag.

procedure: (window-iconified? window)

procedure: (window-iconified-set! window v)

Access the window iconification state.

procedure: (window-visible? window)

procedure: (window-visible-set! window v)

Access the window visibility state.

procedure: (window-resizable? window)

Checks whether the window is resizable by the user.

procedure: (window-decorated? window)

Checks whether the window has decorations.

procedure: (window-floating? window)

Checks whether the window is floating.

procedure: (window-focused? window)

Checks whether the window has the input focus.

parameter: current-window

The window with the currently active rendering context, or #f.

procedure: (extension-supported? name)

Determines whether the given client API extension is supported by the current context.

procedure: (extension-entry name)

Retrieves the entry point of the given client API extension procedure for the current context.

procedure: (set-swap-interval! integer)

Set the number of synchronization intervals to wait for buffer swaps of the current context window.

procedure: (window-swap-buffers! window)

Swaps the back and front buffers of the given window.

Clipboard

procedure: (window-clipboard window)

procedure: (window-clipboard-set! window string)

Access the text content of the clipboard for the given window.

Cursors

procedure: (cursor? any)

Checks whether the given object is a GLFW cursor.

ftype: glfw-image

Foreign structure type for custom images.

procedure: (make-cursor image)

procedure: (make-cursor image hot-x hot-y)

Creates a new cursor. The image may be a pointer to a custom image structure, in which case you can also specify a hotspot position in the cursor image, defaulting to the top left corner.

Alternatively you can create a predefined cursor given one of the symbols arrow, ibeam, i-beam, crosshair, hand, hresize, h-resize, vresize or v-resize.

procedure: (window-cursor-set! window cursor)

Sets the cursor for the given window, or restores the default if the cursor is #f.

procedure: (window-cursor-mode window)

procedure: (window-cursor-mode-set! window v)

Access the cursor mode of the window, which is one of the symbols normal, hidden or disabled.

procedure: (window-cursor-position window)

procedure: (window-cursor-position-set! window x y)

Access the horizontal and vertical cursor position of the window in virtual screen coordinates.

Joysticks

procedure: (joystick-present? integer)

Checks whether a joystick with the given index is connected to the system.

procedure: (joystick-name integer)

Retrieves the name of the given joystick.

procedure: (joystick-axes integer)

Retrieves a vector of positions along each of the given joystick's axes.

procedure: (joystick-buttons integer)

Retrieves a vector of booleans representing the state of each of the given joystick's buttons.

Events

procedure: (poll-events)

Process all pending events.

procedure: (wait-events)

Wait for at least one events and process it.

procedure: (post-empty-event)

Inject an empty event into the queue.

syntax: (modifier symbol)

syntax: (modifiers symbol ...)

The modifier enumeration is used to indicate keyboard modifiers with the symbols shift, control, alt, super, keypad. The keypad modifier only occurs for key input events and indicates that a key on the numeric keypad was used.

callback: (proc window 'close)

Notifies the callback that the user requested to close the window and the window-should-close? flag has been set.

callback: (proc window 'position x y)

Notifies the callback that the window's position on the screen has changed.

callback: (proc window 'size x y)

Notifies the callback that the window's size on the screen has changed.

callback: (proc window 'framebuffer-size x y)

Notifies the callback that the size of the window's framebuffer has changed.

callback: (proc window 'iconified v)

Notifies the callback that the window has been iconified or restored.

callback: (proc window 'focused v)

Notifies the callback that the window has gained or lost input focus.

callback: (proc window 'refresh)

Notifies the callback that the window needs to be redrawn.

callback: (proc window 'key key code action modifiers)

Notifies the callback of keyboard input.

The key is either a character, one of the symbols escape, enter, tab, backspace, insert, delete, right, left, down, up, page-up, page-down, home, end, caps-lock, scroll-lock, num-lock, print-screen, pause, f1 through f25, left-shift, left-control, left-alt, left-super, right-shift, right-control, right-alt, right-super, menu or #f if the key cannot be identified.

The code is a platform-specific scan code for the key.

The action is either press, repeat or #f if the key was released.

The modifiers are an enumeration set as described above.

callback: (proc window 'char char)

Notifies the callback that the user has input a character.

callback: (proc window 'cursor-position x y)

Notifies the callback that the cursor has moved in the window.

callback: (proc window 'cursor-inside v)

Notifies the callback that the cursor has moved into or out of the window.

callback: (proc window 'mouse-button button action modifiers)

Notifies the callback that a mouse was pushed or released in the window. The button is specified as an integer index, the action is #t for a pushed button or #f for a released button and the modifiers are an enumeration set as described above.

callback: (proc window 'scroll x y)

Notifies the callback that the window has been scrolled.

callback: (proc window 'drop paths)

Notifies the callback that files have been dropped on the window. The files are passed as a list of absolute paths.