LibRaylib Bindings for Crystal.

Related tags

Game gamedev
Overview

logo

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.

Supported platforms

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

  1. x86_64-linux-gnu = 64-bit Linux
  2. x86_64-windows = 64-bit Windows

Installation

Linux

  1. Install raylib from github
  2. Run make install in raylib
  3. Add raylib-cr to your shard.yml:
dependencies:
  raylib-cr:
    github: sol-vin/raylib-cr
  1. Run shards install
  2. Get programming!

Windows

  1. Install crystal with scoop install crystal
  2. Copy ./rsrc/native/windows/raylib to C:\raylib
  3. Run in powershell
$env:LIB="${env:LIB};C:\raylib\lib"
$env:PATH="${env:PATH};C:\raylib\lib"
  1. Go back to your project directory. Add raylib-cr to your shard.yml:
dependencies:
  raylib-cr:
    github: sol-vin/raylib-cr
  1. Run mkdir lib && cd lib && git clone https://github.com/sol-vin/raylib-cr
  2. Get programming!

Usage Example

require "raylib-cr"

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

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

LibRaylib.close_window

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

Contributors

Inactive Contributors

You might also like...
HP-Socket bindings for aardio

HP-Socket-bindings-for-aardio HP-Socket is a high performance network framework. aardio is an extremely easy-to-use dynamic language, but it is also a

Godot bindings for the Rapier3D physics engine

Godot bindings for the Rapier3D physics library How to use There are two parts: A Godot module which must be compiled with the engine.

LLVM bindings for Node.js/JavaScript/TypeScript

llvm-bindings LLVM bindings for Node.js/JavaScript/TypeScript Supported OS macOS Ubuntu Windows Supported LLVM methods listed in the TypeScript defini

RayLib extern bindings for Haxe
RayLib extern bindings for Haxe

raylib-haxe Haxe bindings for RayLib usage haxelib git raylib-haxe https://github.com/haxeui/raylib-haxe package; import RayLib.*; import RayLib.Cam

C# bindings for Sokol using Sokol's binding generator

C# bindings for Sokol using Sokol's binding generator

Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming
Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming

Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming, Currently works only for windows but feel free the expand t

Android Bindings for QuickJS, A fine little javascript engine.

quickjs-android quickjs-android 是 QuickJS JavaScript 引擎的 Android 接口框架,整体基于面向对象设计,提供了自动GC功能,使用简单。armeabi-v7a 的大小仅 350KB,是 Google V8 不错的替代品,启动速度比 V8 快,内

Python bindings for Wasm3, the fastest WebAssembly interpreter

pywasm3 Python bindings for Wasm3, the fastest WebAssembly interpreter Main repository: Wasm3 project Install # Latest release: pip3 install pywasm3

Zig bindings for the excellent CRoaring library

Zig-Roaring This library implements Zig bindings for the CRoaring library. Naming Any C function that begins with roaring_bitmap_ is a method of the B

LibreTranslate C++ bindings

LibreTranslate-cpp LibreTranslate C++17 bindings. Example usage #include iostream #include "LibreTranslate.h" int main(){ LibreTranslateAPI libr

lua-nuspell is a set of Lua 5.x bindings for Nuspell spellchecking C++ library.

lua-nuspell lua-nuspell is a set of Lua 5.x bindings for Nuspell spellchecking C++ library. About Nuspell Nuspell is a fast and safe spelling checker

Python bindings of silk codec.

Python silk module. --- pysilk --- APIs See test\test.py. import pysilk as m m.silkEncode(buf , 24000) m.silkDecode(buf , 24000) #the first param is b

PyCppAD — Python bindings for CppAD Automatic Differentiation library

PyCppAD is an open source framework which provides bindings for the CppAD Automatic Differentiation(CppAD) C++ library in Python. PyCppAD also includes support for the CppADCodeGen (CppADCodeGen), C++ library, which exploits CppAD functionality to perform code generation.

SWIG bindings for raylib (to Lua, and hopefully other languages)

swigraylib SWIG binding for raylib This repo generates raylib bindings to other languages (eg. Lua), by providing a raylib.i SWIG interface file. SWIG

rlua -- High level bindings between Rust and Lua

rlua -- High level bindings between Rust and Lua

A next generation media player, with vim-like bindings

MusicKid A next generation media player, with vim-like bindings Installation Clone the repo git clone git-url cd MusicKid/Final Install dependencies

Ziggified GLFW bindings with 100% API coverage, zero-fuss installation, cross compilation, and more.

mach/glfw - Ziggified GLFW bindings Ziggified GLFW bindings that Mach engine uses, with 100% API coverage, zero-fuss installation, cross compilation,

Bindings, from the comfort and speed of C++ and without Qt.

KDBindings Bindings, from the comfort and speed of C++ and without Qt. From plain C++ you get: Signals + Slots. Properties templated on the contained

hb-xlib bindings for Harbour language.

hb-xlib hb-xlib is a Harbour module providing bindings for the Xlib graphics library. This project is intended for people who want to start to program

Comments
  • struct Rectangle is missing initialization parameters

    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
    
    opened by rishavs 2
  • Raymath support

    Raymath support

    This PR adds almost all of the raymath functions. Here are the notes:

    • Vector3ToFloatV and MatrixToFloatV were skipped because I didn't want to introduce additional types. They're noted in the source
    • All of the other functions were put in snake_case and take LibC::Floats or Doubles, and return the same
    • Vector2, Vector3, Matrix, and Quaternion all have methods on them which correspond to the C functions which take that type as the first argument. They also have initializers such as Vector2.zero(). These methods take Number as their argument to avoid repetitive casts, however still return LibC::Float / Double
    • The above types also have the operators +, -, *, / defined, for their own type and for Numbers. These map to x.multiply and x.scale, etc. / was added even though it isn't in raymath, it just scales by 1/x.
    opened by rightbrace 1
  • Support for Mac M1

    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
    
    opened by megatux 0
Owner
Ian Rash
Ian Rash
Godot bindings for the Rapier3D physics engine

Godot bindings for the Rapier3D physics library How to use There are two parts: A Godot module which must be compiled with the engine.

David Hoppenbrouwers 28 Dec 26, 2022
The purpose of this library is to control a piezo crystal and make sound with it

Beeper-Library The purpose of this library is to control a piezo crystal and make sound with it. The piezo may either have electronic or be connected

Dirk Ohme 2 Jan 20, 2022
Distributed (Deep) Machine Learning Community 682 Dec 28, 2022
C++ (with python bindings) library for easily reading/writing/manipulating common animation particle formats such as PDB, BGEO, PTC. See the discussion group @ http://groups.google.com/group/partio-discuss

Partio - A library for particle IO and manipulation This is the initial source code release of partio a tool we used for particle reading/writing. It

Walt Disney Animation Studios 412 Dec 29, 2022
A tool for generating cross-language type declarations and interface bindings.

Djinni Djinni is a tool for generating cross-language type declarations and interface bindings. It's designed to connect C++ with either Java or Objec

Dropbox 2.8k Jan 3, 2023
C++11 API for creating Lua bindings

=head1 NAME luacxx - C++11 binding and modules for Lua =head1 SYNOPSIS // Create a new Lua environment to play with. auto env = lua::create

Aaron Faanes 148 Nov 14, 2022
🎮 C Bindings/Wrappers for Apple's METAL framework

Apple's Metal for C C Wrapper for Apple's METAL framework. This library is C bindings of Metal API (MetalGL). Since OpenGL is deprecated, this library

Recep Aslantas 116 Dec 30, 2022
🎮 C Bindings/Wrappers for Apple's METAL framework

Apple's Metal for C C Wrapper for Apple's METAL framework. This library is C bindings of Metal API (MetalGL). Since OpenGL is deprecated, this library

Recep Aslantas 116 Dec 30, 2022
RcppFastFloat: Rcpp Bindings for the fastfloat C++ Header-Only Library

Converting ascii text into (floating-point) numeric values is a very common problem. The fast_float header-only C++ library by Daniel Lemire does this very well, and very fast at up to or over to 1 gigabyte per second as described in more detail in a recent arXiv paper.

Dirk Eddelbuettel 18 Nov 15, 2022
ChakraCore bindings for aardio

ChakraCore-bindings-for-aardio ChakraCore is a Javascript engine with a C API you can use to add support for Javascript to any C or C compatible proje

null 9 Feb 18, 2022