module CrystGLFW

Extended Modules

Defined in:

crystglfw.cr
crystglfw/action.cr
crystglfw/client_api.cr
crystglfw/connection_status.cr
crystglfw/context_api.cr
crystglfw/context_robustness.cr
crystglfw/error.cr
crystglfw/events/any.cr
crystglfw/events/event.cr
crystglfw/events/joystick_toggle_connection.cr
crystglfw/events/modifiers.cr
crystglfw/events/monitor_toggle_connection.cr
crystglfw/events/window_char.cr
crystglfw/events/window_close.cr
crystglfw/events/window_cursor_cross_threshold.cr
crystglfw/events/window_cursor_move.cr
crystglfw/events/window_file_drop.cr
crystglfw/events/window_framebuffer_resize.cr
crystglfw/events/window_key.cr
crystglfw/events/window_mouse_button.cr
crystglfw/events/window_move.cr
crystglfw/events/window_refresh.cr
crystglfw/events/window_resize.cr
crystglfw/events/window_scroll.cr
crystglfw/events/window_toggle_focus.cr
crystglfw/events/window_toggle_iconification.cr
crystglfw/joystick.cr
crystglfw/key.cr
crystglfw/monitors/gamma_ramp.cr
crystglfw/monitors/monitor.cr
crystglfw/monitors/video_mode.cr
crystglfw/mouse_button.cr
crystglfw/opengl_profile.cr
crystglfw/release_behavior.cr
crystglfw/sticky.cr
crystglfw/version.cr
crystglfw/windows/cursor.cr
crystglfw/windows/hint_label.cr
crystglfw/windows/image.cr
crystglfw/windows/state.cr
crystglfw/windows/window.cr

Constant Summary

DONT_CARE = LibGLFW::DONT_CARE

Class Method Summary

Class Method Detail

def self.on_error(&callback : ErrorCallback) #

Sets the error callback that is called when an error occurs in LibGLFW.

When an error occurs in LibGLFW, an error code is yielded to the block defined by this method. The error code identifies the type of error that occurred and can be validated by checking it against the constants defined in CrystGLFW:

CrystGLFW.on_error do |error_code|
  case error_code
  when CrystGLFW[:not_initialized]
    puts "CrystGLFW has not been initialized."
  when CrystGLFW[:invalid_enum]
    puts "An invalid enum was passed to CrystGLFW."
  else
    puts "An error occurred"
  end
end

NOTE This method may be called outside a #run block definition without triggering an error.

NOTE Defining custom behavior will bypass the Error module entirely. It is recommended that this method not be used.


[View source]
def self.poll_events #

Processes all events in the event queue and then returns immediately.

include CrystGLFW

CrystGLFW.run do
  window = Window.new
  until window.should_close?
    CrystGLFW.poll_events # Process all events, even if queue is empty.
    window.swap_buffers
  end
end

NOTE This method must be called inside a #run block definition.

NOTE This method must not be called from within a callback.


[View source]
def self.post_empty_event #

Posts an empty event to the event queue, forcing #wait_events to return.

CrystGLFW.post_empty_event

NOTE This method must be called inside a #run block definition.


[View source]
def self.run(&) #

Sets up GLFW to execute the block and terminates GLFW afterwards.

include CrystGLFW

CrystGLFW.run do
  window = Window.new(title: "My Window")
  until window.should_close?
    window.wait_events
    window.swap_buffers
  end
end

With few exceptions, all CrystGLFW methods must be called within the block passed to this method. This method initializes the underlying GLFW library for use and cleans up the library after the block has returned.


[View source]
def self.set_time(t : Number) #

Sets the GLFW timer to a new time, in seconds.

This method accepts the following arguments:

  • t, the new time.
CrystGLFW.set_time 1.0
CrystGLFW.time # => 1.0

NOTE This method must be called inside a #run block definition.


[View source]
def self.time : Float64 #

Returns the current value, in seconds, of the GLFW timer.

CrystGLFW.time # => 0.13899576

NOTE This method must be called inside a #run block definition.


[View source]
def self.time=(t : Number) #

Alternate syntax for #set_time.

This method accepts the following arguments:

  • t, the new time.
CrystGLFW.time = 1.0
CrystGLFW.time # => 1.0

NOTE This method must be called from within a #run block definition.


[View source]
def self.timer_frequency : UInt64 #

Returns the frequency, in Hz, of the raw timer.

CrystGLFW.timer_frequency # => 1_000_000_000

NOTE This method must be called inside a #run block definition.


[View source]
def self.timer_value : UInt64 #

Returns the current value of the raw timer, measured in 1 / #timer_frequency seconds.

CrystGLFW.timer_value # => 754_104_002_009_408

NOTE This method must be called inside a #run block definition.


[View source]
def self.version : NamedTuple(major: Int32, minor: Int32, rev: Int32) #

Returns the major, minor, and revision version numbers of GLFW.

CrystGLFW.version # => {major: 3, minor: 2, rev: 1}

NOTE This method may be called outside a #run block definition without triggering an error.


[View source]
def self.version_string : String #

Returns the compile-time generated version string of GLFW.

CrystGLFW.version_string # => "3.2.1 Cocoa NSGL chdir menubar retina dynamic"

NOTE This method may be called outside a #run block definition without triggering an error.


[View source]
def self.wait_events(timeout : Number) #

Puts the calling thread to sleep until at least one event is queued or the specified timeout is reached.

include CrystGLFW

CrystGLFW.run do
  window = Window.new
  until window.should_close?
    CrystGLFW.wait_events(1.5)
    window.swap_buffers
  end
end

This method accepts the following arguments:
- *timeout*, the maximum amount of time, in seconds, to wait.


NOTE: This method must be called inside a `#run` block definition.

NOTE: This method must not be called from within a callback.

[View source]
def self.wait_events #

Puts the calling thread to sleep until at least one event is queued.

include CrystGLFW

CrystGLFW.run do
  window = Window.new
  until window.should_close?
    CrystGLFW.wait_events # Wait for events to queue, then process them.
    window.swap_buffers
  end
end


NOTE: This method must be called inside a `#run` block definition.

NOTE: This method must not be called from within a callback.

[View source]