module

Espresso

Inherits Espresso::ErrorHandling / Espresso::WindowTopic / Espresso::EnumCopy

Lightweight wrapper around GLFW for Crystal.

Constants

VERSION = {{ (`shards version \"/tmp/tmp.BjjMCn/src/src\"`).stringify.chomp }}

Current version of the shard.

Instance methods

compiled_version

Version of GLFW that Espresso was compiled against. This should match #runtime_version to have consistent/expected behavior.

Source
init(joystick_hat_buttons : Bool | Nil = nil, cocoa_chdir_resources : Bool | Nil = nil, cocoa_menubar : Bool | Nil = nil) : Nil

Prepares GLFW so that it can be used. This method must be called prior to any features that require initialization. If the initialization fails, a GLFWError will be raised.

Before exiting the program, and after GLFW is no longer needed, the #terminate method must be called. It is recommended to use #run instead of this method.

Arguments to this method are initialization hints. When unspecified (nil), the hints will use their default value. Specify true or false for the hints as needed.

joystick_hat_buttons specifies whether to also expose joystick hats as buttons, for compatibility with earlier versions of GLFW that did not have this feature.

macOS specific hints:

cocoa_chdir_resources specifies whether to set the current directory to the application to the Contents/Resources subdirectory of the application's bundle, if present.

cocoa_menubar specifies whether to create a basic menu bar, either from a nib or manually, when the first window is created, which is when AppKit is initialized.

Calling this method when GLFW is already initialized does nothing.

A PlatformError will be raised if GLFW couldn't be initialized.

Source
run(joystick_hat_buttons : Bool | Nil = nil, cocoa_chdir_resources : Bool | Nil = nil, cocoa_menubar : Bool | Nil = nil, &)

Initializes GLFW and yields for the duration it is usable. GLFW is automatically terminated after the block completes, even if an uncaught exception is raised.

Arguments to this method are initialization hints. When unspecified (nil), the hints will use their default value. Specify true or false for the hints as needed. See #init for details on what these hints do.

The value of the block is returned by this method.

Calling this method when GLFW is already initialized does nothing.

A PlatformError will be raised if GLFW couldn't be initialized.

Usage:

Espresso.run do
  # Use GLFW here.
end
Source
runtime_version

Version of GLFW that is loaded and in-use by Espresso. This should match #compiled_version to have consistent/expected behavior.

Source
terminate

Cleans up resources used by GLFW and and changes it made to the system. This method must be called after GLFW is no longer used and before the program exits. Once GLFW is terminated, it must be reinitialized before using it again.

Calling this method when GLFW is already terminated does nothing.

A PlatformError can be raised if GLFW couldn't be terminated.

Source
version

Version of GLFW that is loaded and in-use by Espresso.

Source
version_string

Compiled version string produced by GLFW. Includes the version string and additional compilation and environment information.

Source

Nested types