glfw.cr
forked from calebuharrison/LibGLFWLibGLFW
Complete GLFW bindings written in Crystal.
LibGLFW offers Crystal bindings for the full GLFW specification. These bindings are relatively "raw" - with a few notable exceptions, names of functions, constants, and types remain unchanged.
Installation
First, make sure you've got GLFW3:
brew install glfw3
Add this to your application's shard.yml
:
dependencies:
lib_glfw:
github: calebuharrison/LibGLFW
branch: master
Install your dependencies:
shards install
Usage
require "lib_glfw"
# Initialize GLFW
LibGLFW.init
width, height, title, monitor, share = 640, 480, "My First Window!", nil, nil
# Create a window and its associated OpenGL context.
window_handle = LibGLFW.create_window(width, height, title, monitor, share)
# Render new frames until the window should close.
until LibGLFW.window_should_close(window_handle)
LibGLFW.swap_buffers(window_handle)
end
# Destroy the window along with its context.
LibGLFW.destroy_window(window_handle)
# Terminate GLFW
LibGLFW.terminate
Differences From the C API
LibGLFW differs from the standard GLFW API in only a few, simple ways. Each of these differences only exists to make the API fit the style guide of the Crystal language.
Functions/Methods
Method names in LibGLFW do not have the "glfw" prefix that is present in the C API. Additionally, underscores are used to separate words rather than camel case. LibGLFW methods are all called as class methods of the LibGLFW lib.
In C:
// Get and print the current version of GLFW
int major, minor, rev;
glfwGetVersion(&major, &minor, &rev);
printf("Current version of GLFW is %d.%d.%d\n", major, minor, rev);
In Crystal:
# Get and print the current version of GLFW
LibGLFW.get_version(out major, out minor, out rev)
puts "Current version of GLFW is #{major}.#{minor}.#{rev}"
Constants
Prefixes have also been removed from constants, which are accessed directly from the lib.
In C:
// Check to see if the joystick is present and complain if it isn't.
if (!glfwJoystickPresent(GLFW_JOYSTICK_9)) {
printf("Nooooooooooooooo!!!!!!\n");
}
In Crystal:
# Check to see if the joystick is present and complain if it isn't.
puts "Noooooooooooo!!!!!!" unless LibGLFW.joystick_present(LibGLFW::JOYSTICK_9)
Contributing
- Fork it ( https://github.com/calebuharrison/LibGLFW/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- calebuharrison Caleb Uriah Harrison - creator, maintainer
glfw.cr
- 0
- 1
- 0
- 1
- 1
- almost 3 years ago
- April 20, 2019
MIT License
Wed, 06 Nov 2024 23:58:31 GMT