Crystal versioning like rbenv, to switch Crystal versions between directories. Not necessary, but thought it would be good to set up in case the Crystal version I try gets out of date soon.
https://asdf-vm.com/#/core-manage-asdf-vm
Once asdf is installed, you can list all available Crystal versions and install one:
$ asdf list-all crystal
# lists all crystal vers available
$ asdf install crystal 0.27.2
# once we create a new project we'll use
$ asdf local crystal 0.27.2
# to set the local crystal version or use `global` to set for everything
$ crystal init app cray-test
follow https://gitlab.com/Zatherz/cray to cray
dependency:
Add this to your application's shard.yml:
dependencies:
cray:
gitlab: zatherz/cray
then run
$ shards install
to install the newly added cray
dependency.
see https://github.com/raysan5/raylib/wiki/Working-on-macOS
$ brew install raylib
run via:
$ crystal run src/hello_world.cr
(copied hello_world.cr
from the examples folder of the cray
github: https://gitlab.com/Zatherz/cray
Compiling not working. Difficulties in communicating via Raylib to crystal, maybe the binaries are not matched correctly?
15:34:36 ~/code/crystal/cray-test (master)✗ $ crystal build src/examples/hello-world.cr
Undefined symbols for architecture x86_64:
"_GetDefaultFont", referenced from:
___crystal_main in _main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc "${@}" -o '/Users/matt/code/crystal/cray-test/hello-world' -rdynamic -L/usr/local/Cellar/raylib/2.0.0/lib -lraylib -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.27.2/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`
https://github.com/ddfreyne/glove
Examples: https://github.com/ddfreyne/inari
made a new app, and copied the example code in for displaying a card (image texture):
require "glove"
if full_path = Process.executable_path
Dir.cd(File.dirname(full_path))
end
card =
Glove::Entity.new.tap do |e|
e << Glove::Components::Texture.new("assets/card.png")
e << Glove::Components::Transform.new.tap do |t|
t.width = 140_f32
t.height = 190_f32
t.translate_x = 400_f32
t.translate_y = 300_f32
end
end
scene =
Glove::Scene.new.tap do |scene|
scene.spaces << Glove::Space.new.tap do |space|
space.entities << card
end
end
game = Glove::EntityApp.new(800, 600, "Inari")
game.clear_color = Glove::Color::WHITE
game.replace_scene(scene)
game.run
Glove requires copying over shader files, and any assets, so I reused/modified the Makefile structure from https://github.com/ddfreyne/inari so just with
$ make
$ cd dist/releases/cli
$ ./glove-test
the app opens in a new window, displaying the card image!
I didn't end up liking the Glove
library structure too much, so tried going back to Cray, and was successful
Turns out the bindings to Crystal, the get_default_font
wasn't working, so I removed the usage of the fonts and switched to use the RayLib methods that don't specify font, and use the default Cray font.