This is a Ruby C-extension for the excellent GLFW library. Unlike other bindings, this gem goes beyond just providing a 1:1 wrapper of the functions, and has been organized to be used in a more object-oriented, Ruby way.
For Windows users, the dependencies will automatically be fetched and installed into Ruby's environment using the built-in functionality of MSYS2.
For Unix-like systems, simply have GLFW installed globally, and it will be found and linked against during the build process.
$ gem install glfw
Open a terminal/command prompt in the base directory:
$ gem build glfw.gemspec $ gem install glfw-[VERSION].gem
At its simplest, to create a platform-specific window with an OpenGL context requires very little code.
::.(800, 600, "Hello, World!") do |window| until window.closing? . window.swap_buffers # Your rendering code goes here end end
You will likely want to fine-tune the created context to what your application requires. GLFW exposes these as "hints", which can be set before a window is created.
# Initialize GLFW core . # Load default window hints. This will reset any previous hints given ::. # Window will be NOT be decorated (title, border, close widget, etc) ::.(::, false) # Specify MINIMUM required OpenGL version ::.(::, 3) ::.(::, 3)
All constants for creation hints are prefixed with
GLFW offers a high-level of control of the application window, including callbacks for nearly every relevant system event that effects the window (see documentation for what all callbacks are available). Callbacks are implemented by using Ruby blocks to create a closure that will be invoked the callback fires.
All callbacks in the libaray follow the same idioms:
window.on_framebuffer_resize do |width, height| # Block will be called when framebuffer size changes (change projection matrix, viewport, etc.) end window.on_key do |key, scancode, action, mods| # Block called when keyboard input changes (process keystroke) end # Use method without block to unsubscribe from callback window.on_key
Prior versions of the gem used a method of enabling all callbacks via a single method, which would then invoke a pre-defined method that had to be overridden/aliased. Starting with version 3.3.2, this functiionality has been removed in favor of using Ruby blocks, which is more familiar and Ruby-like, as well as being more flexible.
The gem documention can be found here, it covers at least minimal coverage of the entire API surface.
For more in depth explanation of some features, the native GLFW library offers a very in-depth and detailed documentation that may be used as to augment it, or even as a stand-alone source of information to understanding the library. While not all features will match up with a 1:1 ratio, the naming conventions and idioms are the same and self-explanatory to use the C documentation for the Ruby gem.
Bug reports and pull requests are welcome on GitHub at https://github.com/ForeverZer0/glfw. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the GLFW project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.