Giter VIP home page Giter VIP logo

raylib-cr's Introduction

logo

Windows - Build Examples Ubuntu - Build Examples

raylib-cr

Crystal Bindings for raylib, a small and easy to use game development library.
As for now the bindings only support the raw function calls from raylib itself. raymath functions are also supported, as are infix operators for vectors, matricies, and quaternions.

Supported platforms

These platforms are supported out of the box and are linked statically

  1. 64-bit Linux
  2. 64-bit Windows

Weak/Broken support

  1. MacOS

Hopefully soon

  • Raspberry PI

Installation

Linux

  1. Run
sh rsrc/native/ubuntu/install.sh
  1. Add raylib-cr to your shard.yml:
dependencies:
  raylib-cr:
    github: sol-vin/raylib-cr
  1. Run shards install
  2. Get programming!

Windows

  1. Follow the instructions at https://github.com/neatorobito/scoop-crystal to add the crystal-preview bucket to scoop
  2. Install crystal with scoop install crystal
  3. powershell ./rsrc/native/windows/install.ps1
  4. Run in powershell
$env:LIB="${env:LIB};C:\raylib"
$env:PATH="${env:PATH};C:\raylib"

OR

Run in cmd

set PATH=%PATH%;C:\raylib
set LIB=%LIB%;C:\raylib
  1. Add raylib-cr to your shard.yml:
dependencies:
  raylib-cr:
    github: sol-vin/raylib-cr
  1. Run shards install
  2. Get programming!

MacOS

  1. Run
sudo sh rsrc/native/mac/mac-raylib-install.sh
  1. Add raylib-cr to your shard.yml:
dependencies:
  raylib-cr:
    github: sol-vin/raylib-cr
  1. Run shards install
  2. Get programming!

Usage Example

main.cr

require "raylib-cr"

Raylib.init_window(800, 450, "Hello World")
Raylib.set_target_fps(60)

until Raylib.close_window?
  Raylib.begin_drawing
  Raylib.clear_background(Raylib::RAYWHITE)
  
  Raylib.draw_text("Hello World!", 190, 200, 20, Raylib::BLACK)
  Raylib.end_drawing
end

Raylib.close_window
  1. Add raylib-cr to shard.yml dependencies.
  2. shards install
  3. Run in powershell (only needs to be run once per new console window opened)
$env:LIB="${env:LIB};C:\raylib"
$env:PATH="${env:PATH};C:\raylib"
  1. shards run

RayGUI, RLGL, Audio, and Lights

If you need to extra functionality, RLGL, RAudio and Lights can be included with the following.

require "raylib-cr/raygui"
require "raylib-cr/rlgl"
require "raylib-cr/audio"
require "raylib-cr/lights"

Contributing

  1. Fork it (https://github.com/sol-vin/raylib-cr)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Owner

Major Contributors

Minor Contributors

Inactive Contributors

raylib-cr's People

Contributors

aregevdev avatar avrame avatar b1tlet avatar bararchy avatar d-shwagginz avatar eddyluten avatar rightbrace avatar rishavs avatar shawsumma avatar sol-vin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

raylib-cr's Issues

Support for Mac M1

I installed the latest Crystal & raylib on my M1 and cloned the repo.
Some examples seem to work fine, others like shape don't.
Will try to learn the library & test more things later to improve this ticket and try to make it fully work on this platform.
Also, I have an X64 Manjaro Linux to compare.

Crystal 1.3.2 [932f193ae] (2022-01-18)

LLVM: 10.0.0
Default target: aarch64-apple-darwin

Miniaudiohelpers error

while trying running example i get this error

/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: cannot find -lminiaudiohelpers (this usually means you need to install the development package for libminiaudiohelpers): No such file or directory
collect2: error: ld returned 1 exit status
Error: execution of command failed with exit status 1: cc "${@}" -o /home/pawel/.cache/crystal/home-pawel-Dokumenty-crystal_proj-learn-lib-raylib-cr-src-raylib-cr-miniaudio_fix-ma_sizes.cr/macro_run -rdynamic -L/usr/lib64/crystal -lminiaudiohelpers -lpcre2-8 -lm -lgc -lpthread -levent -lrt -lpthread -ldl

install.sh cleanup asks for confirmation for every file

When running the install.sh script during the final deletion steps:

rm -r raygui
rm -r raylib

Confirmation is needed for every single file:

rm: remove write-protected regular file 'raygui/.git/objects/pack/pack-c928635f2bd28835e7ff73890fec18b8f1b0d2b5.pack'? y
rm: remove write-protected regular file 'raygui/.git/objects/pack/pack-c928635f2bd28835e7ff73890fec18b8f1b0d2b5.idx'? y
rm: remove write-protected regular file 'raylib/build/raylib/CMakeFiles/raylib.dir/compiler_depend.internal'? y
rm: remove write-protected regular file 'raylib/build/raylib/CMakeFiles/raylib.dir/compiler_depend.make'? y
rm: remove write-protected regular file 'raylib/build/raylib/external/glfw/src/CMakeFiles/glfw.dir/compiler_depend.internal'? y
rm: remove write-protected regular file 'raylib/build/raylib/external/glfw/src/CMakeFiles/glfw.dir/compiler_depend.make'? y
rm: remove write-protected regular file 'raylib/build/install_manifest.txt'? y
rm: remove write-protected regular file 'raylib/build/examples/CMakeFiles/raylib_opengl_interop.dir/compiler_depend.internal'? y
rm: remove write-protected regular file 'raylib/build/examples/CMakeFiles/raylib_opengl_interop.dir/compiler_depend.make'? y
rm: remove write-protected regular file 'raylib/build/examples/CMakeFiles/shapes_lines_bezier.dir/compiler_depend.internal'? y
rm: remove write-protected regular file 'raylib/build/examples/CMakeFiles/shapes_lines_bezier.dir/compiler_depend.make'? y
rm: remove write-protected regular file 'raylib/build/examples/CMakeFiles/core_2d_camera_platformer.dir/compiler_depend.internal'? y

etc.

Adding the -f flag would stop the prompting for each file.

I'll open a PR for this change and link it here.

PS: It would probably also be a good idea to add a small cleanup script to remove symlinks and build artifacts if install.sh is run again.

Raylib.load_font segfaults

Summary

The font handling within raylib-cr fails, using both v4.2 and v5.0.
I'm on MacOSX.
I have another project in C that uses the raylib apis directly, which works with both 4.2 and 5.

I don't see anything off with the bindings unfortunately, so I wonder if there is something else at play.

Minimal reproducible example

require "raylib-cr"

Raylib.load_font("#{__DIR__}/PTMono.ttf")

Stacktrace

INFO: FILEIO: [/Users/skinnyjames/src/bugs/PTMono.ttf] File loaded successfully
Invalid memory access (signal 11) at address 0x0
[0x107a2fe0b] *Exception::CallStack::print_backtrace:Nil +107 in /Users/skinnyjames/.cache/crystal/crystal-run-test.tmp
[0x107a153bd] ~procProc(Int32, Pointer(LibC::SiginfoT), Pointer(Void), Nil)@/Users/skinnyjames/.asdf/installs/crystal/1.11.2/src/crystal/system/unix/signal.cr:131 +285 in /Users/skinnyjames/.cache/crystal/crystal-run-test.tmp
[0x7ff81242d37d] _sigtramp +29 in /usr/lib/system/libsystem_platform.dylib

Expected

Raylib.load_font doesn't segfault.

Actual

Raylib.load_font segfaults.

MacOS build instructions?

I see there has been a recent commit that says "macos support out of the box", and there are several shell scripts in rsrc that start with mac-.
I tried running mac-raylib-build.sh but I get the following error:

CMake Error: The source directory "/Users/avram/Dev/crystal-code/raylib-cr/rsrc/raylib" does not appear to contain CMakeLists.txt.

Are there instructions for building in MacOS? Is it possible to build in MacOS at this point? I have an x86 and an Arm mac, so either works for me.

Improper drawing in shapes_top_down_lights example

Currently, the example only renders when the variable lights_dirty is true. However, this makes the example hang since keyboard and mouse functionality are frame-based and refreshed only when a drawing is performed. You'd need to have at least some R.begin_drawing .. R.end_drawing in every loop cycle..

struct Rectangle is missing initialization parameters

The Rectangle (and all other) struct doesn't have a initialization constructor.

Due to this, initializing Rectangle with argument throws exception.

using

LibRaylib::Rectangle.new(100, 100, 100, 100)

throws the error

In src\sceneMainMenu.cr:22:55

 22 | if LibRayGUI.button( LibRaylib::Rectangle.new(100, 100, 100, 100), "Press me!" )
                                                ^--
Error: wrong number of arguments for 'LibRaylib::Rectangle.new' (given 4, expected 0)

Overloads are:
 - LibRaylib::Rectangle.new()

The way to make this work is to update the properties of Rectangle after it is initialized.
This works;

            LibRaylib.draw_text("Scene Main Menu", 190, 200, 20, LibRaylib::BLACK)
            btnRec = LibRaylib::Rectangle.new
            btnRec.x = 100
            btnRec.y = 100
            btnRec.width = 100
            btnRec.height = 100
            if LibRayGUI.button( btnRec, "Press me!" ) 
                pp "Pressed";
            end

but this is cumbersome to write and deviates from the raylib api where users can create Rectangle with inline parameters like this;

            if LibRayGUI.button( LibRaylib::Rectangle.new(100, 100, 100, 100), "Press me!" )
                pp "Pressed";
            end

Recommendation would be to update the Rectangle struct.
instead of having the Rectangle struct like this;

  struct Rectangle
    x : LibC::Float
    y : LibC::Float
    width : LibC::Float
    height : LibC::Float
  end

we can go for more idiomatic properties with default values and overloaded constructors;

  struct Rectangle
    property x : LibC::Float = 0
    property y : LibC::Float = 0
    property width : LibC::Float = 120
    property height : LibC::Float = 30
    
    def initialize
    end

    def initialize(x, y, width, height)
      @x = x
      @y = y
      @width = width
      @height = height
    end
  end

I can't install Raylib on Zorin OS (Linux)

Zorin OS is an Ubuntu derivative
I ran the rsrc/install.sh script as described in the readme but I get this error:

raygui/src/raygui.c:322:14: fatal error: raylib.h: No such file or directory
  322 |     #include "raylib.h"
      |              ^~~~~~~~~~
compilation terminated.
gcc: error: raygui/raygui.o: No such file or directory

Can't run the raygui_button example

The other examples work fine, but raygui_button doesn't run.

I type in my terminal: crystal run src/raygui_button.cr
I get this error:

ld: library 'raygui' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with exit status 1: cc "${@}" -o /Users/avrameisner/.cache/crystal/crystal-run-raygui_button.tmp  -rdynamic -L/opt/homebrew/Cellar/crystal/1.11.1/bin/../../../../lib -lraygui -lraylib -framework IOKit -framework Cocoa -framework OpenAL -framework OpenGL -lpcre2-8 -L/opt/homebrew/Cellar/bdw-gc/8.2.4/lib -lgc -lpthread -L/opt/homebrew/Cellar/libevent/2.1.12_1/lib -levent -liconv

I am on an MacBook Pro M1 running macOS Sonoma 14.2.1 (23C71)

miniaudiohelpers library uses full implementation unnecessarily

The sole purpose of miniaudiohelpers.c is to determine some struct sizes. On all platforms. the C compiler can calculate struct sizes based on the struct definitions. Therefore, instead of a nearly > 1 MB large miniaudiohelpers library that also fully implements the miniaudio library, one can get an ~ 1 KB large one that is perfectly sufficient.

FIX: remove the #define MINIAUDIO_IMPLEMENTATION in miniaudiohelpers.c

// #define MINIAUDIO_IMPLEMENTATION

#include "miniaudio.h"

size_t MADataConverterSize();
size_t MAContextSize();
size_t MADeviceSize();
size_t MAMutexSize();

size_t MADataConverterSize()
{
  return sizeof(ma_data_converter);
}

size_t MAContextSize()
{
  return sizeof(ma_context);
}

size_t MADeviceSize()
{
  return sizeof(ma_device);
}

size_t MAMutexSize()
{
  return sizeof(ma_mutex);
}

A few of the examples don't work on my Intel MacBook

fogshader and rlgl_solar_system give me this error:

Undefined symbols for architecture x86_64:
  "_SetCameraMode", 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 exit status 1: cc "${@}" -o /Users/avram/.cache/crystal/crystal-run-fogshader.tmp  -rdynamic -L/usr/local/Cellar/crystal/1.8.2/libexec/../../../../lib -lraylib -framework IOKit -framework Cocoa -framework OpenAL -framework OpenGL -lpcre2-8 -lgc -L/usr/local/Cellar/libevent/2.1.12/lib -levent -liconv

Also, sound_test was missing the raylib-cr dependency in it's shard.yml file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.