Main entry point to the GLFW library
You must only instance it once at a time.
Calling GLFW.destroy
will invalidate the instance and all the resources associated.
Using the object, or objects created thought it, after the destruction will throw a UseAfterDestroyException
exception.
Static variables
staticread onlyversion:{patch:Int, minor:Int, major:Int}
The version of the native GLFW library used. Can be called without having a `GLFW` instance.
Thread safety: This function may be called from any thread.
Constructor
new()
Create a new instance of GLFW.
Only one instance must be valid at a time.
Trying to create a second one will throw a AlreadyInitializedException
exception.
Thread safety: This function must only be called from the main thread.
Throws:
AlreadyInitializedException | |
---|---|
null | PlatformErrorException |
Variables
clipboardString:String
The contents of the clipboard as a string.
This is the contents of the system clipboard, if it contains or is convertible to a UTF-8 encoded string.
If the clipboard is empty or if its contents cannot be converted, the result is an empty string.
Thread safety: This function must only be called from the main thread.
Throws:
PlatformErrorException | |
---|---|
null | UseAfterDestroyException |
read onlygamepads:ReadOnlyArray<Gamepad>
Array of possible gamepads.
This is a set of 15 preallocated Gamepad
instances, the gamepads are not necessarily connected, check with Gamepad.connected
or use GLFW.getConnectedGamepads
to only get the gamepads that are connected.
Use GLFW.onGamepadChange
or Gamepad.onStatusChange
to be notified of gamepad connections and disconnections.
read onlymonitors:ReadOnlyArray<Monitor>
The currently connected monitors.
The primary monitor is always first in the array.
The Monitor
instances are only valid until the instance is destroyed or the monitor gets disconnected.
Throws:
null | UseAfterDestroyException |
---|
onGamepadChange:Array<(gamepad:Gamepad, connected:Bool) ‑> Void>
The callbacks to be called when a gamepad is connected or disconnected from the system.
Disconnecting then reconnecting the same physical gamepad is not guaranteed to map to the same Gamepad
object.
Arguments:
gamepad
The gamepad that was connected or disconnected.connected
True if the gamepad was connected, false if disconnected.
To add a callback push a function to this array.
onMonitorChange:Array<(monitor:Monitor, connected:Bool) ‑> Void>
The callbacks to be called when a monitor is connected to or disconnected from the system.
Arguments:
monitor
The monitor that was connected or disconnected.connected
True if the monitor was connected, false if disconnected.
If the monitor was disconnected the Monitor
instance is valid until the callback returns.
Disconnecting then connecting back a monitor will not reuse the old Monitor
object.
To add a callback push a function to this array.
read onlyprimaryMonitor:Monitor
The primary monitor, usually the monitor where elements like the task bar or global menu bar are located.
This is equalivalent to monitors[0]
.
If no monitor is available then accessing this will throw a NoMonitorException
exception.
Throws:
NoMonitorException | |
---|---|
null | UseAfterDestroyException |
Methods
createCursor(image:Image, x:Int, y:Int):Cursor
Creates a new custom cursor image that can be set for a window with Window.cursor
.
The cursor can be destroyed Cursor.destroy
, any remaining cursors are destroyed by GLFW.destroy
.
The cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image. Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down.
Thread safety: This function must only be called from the main thread.
Parameters:
image | The desired cursor image. |
---|---|
x | The desired x-coordinate, in pixels, of the cursor hotspot. |
y | The desired y-coordinate, in pixels, of the cursor hotspot. |
Returns:
The created cursor.
Throws:
PlatformErrorException | |
---|---|
null | UseAfterDestroyException |
createStandardCursor(shape:CursorShape):Cursor
Creates a cursor with a standard shape, that can be set for a window with Window.cursor
.
The images for these cursors come from the system cursor theme and their exact appearance will vary between platforms.
Most of these shapes are guaranteed to exist on every supported platform but a few may not be present. See the table below for details.
Cursor shape | Windows | macOS | X11 | Wayland |
---|---|---|---|---|
CursorMode.Arrow | Yes | Yes | Yes | Yes |
CursorMode.IBeam | Yes | Yes | Yes | Yes |
CursorMode.Crosshair | Yes | Yes | Yes | Yes |
CursorMode.PointingHand | Yes | Yes | Yes | Yes |
CursorMode.ResizeEW | Yes | Yes | Yes | Yes |
CursorMode.ResizeNS | Yes | Yes | Yes | Yes |
CursorMode.ResizeNWSE | Yes | Yes (1) | Maybe (2) | Maybe (2) |
CursorMode.ResizeNESW | Yes | Yes (1) | Maybe (2) | Maybe (2) |
CursorMode.ResizeAll | Yes | Yes | Yes | Yes |
CursorMode.NotAllowed | Yes | Yes | Maybe (2) | Maybe (2) |
(1) This uses a private system API and may fail in the future.
(2) This uses a newer standard that not all cursor themes support.
Thread safety: This function must only be called from the main thread.
Parameters:
shape | One of the standard shapes in |
---|
Returns:
The created cursor.
Throws:
CursorUnavailableException | |
---|---|
PlatformErrorException | |
null | UseAfterDestroyException |
createWindow(options:WindowOptions):Window
Create a window with the options options
.
To create a fullscreen window, you need to specify the monitor the window will cover in WindowOptions.monitor
. If no monitor is specified, the window will be windowed mode.
Unless you have a way for the user to choose a specific monitor, it is recommended that you pick the primary monitor using primaryMonitor
.
You can get information on the available monitors in the monitors
array.
For fullscreen windows, the specified size becomes the resolution of the window's desired video mode. As long as a fullscreen window is not iconified, the supported video mode most closely matching the desired video mode is set for the specified monitor.
Once you have created the window, you can switch it between windowed and fullscreen mode with Window.setFullscreenMonitor
.
By default, newly created windows use the placement recommended by the window system.
To create the window at a specific position, make it initially invisible using WindowOptions.visible
, set its position with Window.setPosition
and then show it with Window.show
.
As long as at least one fullscreen window is not iconified, the screensaver is prohibited from starting.
Window systems put limits on window sizes.
Very large or very small window dimensions may be overridden by the window system on creation. Check the actual size with Window.getSize
after creation.
Window creation will fail if the Microsoft GDI software OpenGL implementation is the only one available.
On MacOS the window has no icon, as it is not a document window, but the dock icon will be the same as the application bundle's icon. For more information on bundles, see the Bundle Programming Guide in the Mac Developer Library.
On X11 some window managers will not respect the placement of initially hidden windows.
On X11 due to the asynchronous nature of X11, it may take a moment for a window to reach its requested state. This means you may not be able to query the final size, position or other attributes directly after window creation.
On wayland a fullscreen window will not attempt to change the mode, no matter what the requested size or refresh rate.
On wayland screensaver inhibition requires the idle-inhibit protocol to be implemented in the user's compositor.
Thread safety: This function must only be called from the main thread.
Parameters:
options | The options used to create the window. |
---|
Returns:
The created window.
Throws:
FormatUnavailableException | |
---|---|
PlatformErrorException | |
null | UseAfterDestroyException |
destroy():Void
Destroy this instance.
This function destroys all remaining windows and cursors and frees any other allocated resources.
Once this function is called, you must again create a new instance of GLFW
.
This function should be called before the application exits.
Using the object, or objects created thought it, after the destruction will throw a UseAfterDestroyException
exception.
Reentrancy: This function must not be called from a callback.
Thread safety: This function must only be called from the main thread.
Throws:
UseAfterDestroyException | |
---|---|
PlatformErrorException | |
null | UseAfterDestroyException |
getConnectedGamepads():Array<Gamepad>
Get the connected gamepads.
This is a subset from GLFW.gamepads
implemented with:
return gamepads.filter(g -> g.connected);
Throws:
null | UseAfterDestroyException |
---|
pollEvents():Void
Processes all pending events.
This function processes only those events that are already in the event queue and then returns immediately. Processing events will cause the window and input callbacks associated with those events to be called.
On some platforms, a window move, resize or menu operation will cause event processing to block. This is due to how event processing is designed on those platforms.
You can use the Window.onRefresh
callback to redraw the contents of your window when necessary during such operations.
Do not assume that callbacks you set will only be called in response to event processing functions like this one. While it is necessary to poll for events, window systems that require GLFW to register callbacks of its own can pass events to GLFW in response to many window system function calls. GLFW will pass those events on to the application callbacks before returning.
Reentrancy: This function must not be called from a callback.
Thread safety: This function must only be called from the main thread.
Throws:
PlatformErrorException | |
---|---|
null | UseAfterDestroyException |
postEmptyEvent():Void
Posts an empty event to the event queue.
This is causing GLFW.waitEvents
or GLFW.waitEventsTimeout
to return.
Thread safety: This function may be called from any thread.
Throws:
PlatformErrorException | |
---|---|
null | UseAfterDestroyException |
updateGamepadMappings(patch:String):Void
Adds the specified SDL_GameControllerDB gamepad mappings.
This parses the specified ASCII encoded string and updates the internal list with any gamepad mappings it finds.
This string may contain either a single gamepad mapping or many mappings separated by newlines.
The parser supports the full format of the gamecontrollerdb.txt
source file including empty lines and comments.
If there is already a gamepad mapping for a given GUID in the internal list, it will be replaced by the one passed to this function.
If the library is terminated and re-initialized the internal list will revert to the built-in default.
Thread safety: This function must only be called from the main thread.
Parameters:
patch | The string containing the gamepad mappings patch. |
---|
Throws:
null | UseAfterDestroyException |
---|
waitEvents():Void
Waits until events are queued and processes them.
This function puts the calling thread to sleep until at least one event is available in the event queue.
Once one or more events are available, it behaves exactly like GLFW.pollEvents
, i.e. the events in the queue are processed and the function then returns immediately.
Processing events will cause the window and input callbacks associated with those events to be called.
Since not all events are associated with callbacks, this function may return without a callback having been called even if you are monitoring all callbacks.
On some platforms, a window move, resize or menu operation will cause event processing to block.
This is due to how event processing is designed on those platforms.
You can use the Window.onRefresh
callback to redraw the contents of your window when necessary during such operations.
Do not assume that callbacks you set will only be called in response to event processing functions like this one. While it is necessary to poll for events, window systems that require GLFW to register callbacks of its own can pass events to GLFW in response to many window system function calls. GLFW will pass those events on to the application callbacks before returning.
Reentrancy: This function must not be called from a callback.
Thead safety: This function must only be called from the main thread.
Throws:
PlatformErrorException | |
---|---|
null | UseAfterDestroyException |
waitEventsTimeout(timeout:Float):Void
Waits with timeout until events are queued and processes them.
This function puts the calling thread to sleep until at least one event is available in the event queue, or until the specified timeout is reached.
If one or more events are available, it behaves exactly like GLFW.pollEvents
, i.e. the events in the queue are processed and the function then returns immediately.
Processing events will cause the window and input callbacks associated with those events to be called.
The timeout value must be a positive finite number.
Since not all events are associated with callbacks, this function may return without a callback having been called even if you are monitoring all callbacks.
On some platforms, a window move, resize or menu operation will cause event processing to block.
This is due to how event processing is designed on those platforms.
You can use the Window.onRefresh
callback to redraw the contents of your window when necessary during such operations.
Do not assume that callbacks you set will only be called in response to event processing functions like this one. While it is necessary to poll for events, window systems that require GLFW to register callbacks of its own can pass events to GLFW in response to many window system function calls. GLFW will pass those events on to the application callbacks before returning.
Reentrancy: This function must not be called from a callback.
Thread safety: This function must only be called from the main thread.
Parameters:
timeout | The maximum amount of time, in seconds, to wait. |
---|
Throws:
PlatformErrorException | |
---|---|
null | UseAfterDestroyException |