Giter Site home page Giter Site logo

wilsonsilva / raylib-ruby Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 0.0 6.8 MB

Ruby bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.

Home Page: https://raylib-ruby.com

License: zlib License

Ruby 99.94% Shell 0.06%
game game-development game-engine raylib raylib-c ruby ruby-game ruby-games ruby-gem raylib-rb

raylib-ruby's Introduction

Raylib for Ruby

raylib-ruby logo

Ruby bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.

Features

  • Feature parity with raylib 4.5
  • NO external dependencies besides raylib, all required libraries are bundled into raylib
  • Multiple platforms supported: Windows, Linux, MacOS, RPI... and more!
  • Hardware accelerated with OpenGL (1.1, 2.1, 3.3, 4.3 or ES 2.0)
  • Unique OpenGL abstraction layer (usable as standalone module): rlgl
  • Multiple Fonts formats supported (TTF, Image fonts, AngelCode fonts)
  • Multiple texture formats supported, including compressed formats (DXT, ETC, ASTC)
  • Full 3D support, including 3D Shapes, Models, Billboards, Heightmaps and more!
  • Flexible Materials system, supporting classic maps and PBR maps
  • Animated 3D models supported (skeletal bones animation) (IQM)
  • Shaders support, including model and postprocessing shaders.
  • Powerful math module for Vector, Matrix and Quaternion operations: raymath
  • Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD)
  • VR stereo rendering support with configurable HMD device parameters
  • Huge examples collection with +65 code examples!
  • Free and open source.
  • Linter for best practices: rubocop-raylib

Installation

  1. Follow the instructions on the native raylib wiki to install the native raylib library on your operating system.

  2. Install the gem by executing: bundle add raylib or gem install raylib --pre

Usage

Raylib can be used in two ways: namespaced or global.

Namespaced

The namespaced usage is recommended as it avoids global namespace pollution:

require 'raylib'

Raylib.init_window(800, 450, 'My window')

until Raylib.window_should_close
  Raylib.begin_drawing
  Raylib.clear_background(Raylib::WHITE)
  Raylib.draw_text('Congrats! You created your first window!', 190, 200, 20, Raylib::BLACK)
  Raylib.end_drawing
end

Raylib.close_window

Global

If you prefer to use Raylib globally, you can require the raylib/dsl:

require 'raylib/dsl'

init_window(800, 450, 'My window')

until window_should_close
  begin_drawing
  clear_background(WHITE)
  draw_text('Congrats! You created your first window!', 190, 200, 20, BLACK)
  end_drawing
end

close_window

In the code above, require 'raylib/dsl is a shorthand for require 'raylib' + include Raylib.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/raylib-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the zlib/libpng License.

Code of Conduct

Everyone interacting in the Raylib project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

raylib-ruby's People

Contributors

wilsonsilva avatar

Stargazers

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

Watchers

 avatar

raylib-ruby's Issues

Callbacks slow down the applications

Here's an example:

ProcessAudio = FFI::Function.new(:void, [:pointer, :uint]) do |buffer, frames|
# samples = buffer.to_a
# average = 0.0 # Temporary average volume
#
# frames.times do |frame|
# left = samples[frame * 2]
# right = samples[frame * 2 + 1]
#
# left = (left.abs ** $exponent) * (left < 0.0 ? -1.0 : 1.0)
# right = (right.abs ** $exponent) * (right < 0.0 ? -1.0 : 1.0)
#
# average += (left.abs / frames) + (right.abs / frames)
# end
#
# # Moving history to the left
# $average_volume.shift(399)
# $average_volume << average # Adding last average value
end
# Initialization
# --------------------------------------------------------------------------------------
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450
Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [audio] example - processing mixed output")
Raylib.init_audio_device # Initialize audio device
# Raylib.attach_audio_mixed_processor(ProcessAudio) # FIXME: Uncomment when callbacks are supported

Web support

Ruby has recently introduced support for web compilation. I'm not sure how well it works with Emscriptien/FFI libraries.

Lack of documentation for importing and using Models

I'm trying to load an OBJ format model into my program but it's unclear how to actually use the create function of the model. Documentation for loading / using / animating models would be very appreciated.

Load functions can't handle relative paths

For example Raylib.load_model("resources/models/iqm/guy.iqm") only works if I write it as Raylib.load_model("/Users/wilson/projects/rb/raylib/examples/models/resources/models/iqm/guy.iqm")

Configurable MAX_BATCH_ELEMENTS

In textures_bunnymark.c/rb, it is possible to configure MAX_BATCH_ELEMENTS. This is a compile-time macro that is not available in Ruby. It should be exposed.

// This is the maximum amount of elements (quads) per batch
// NOTE: This value is defined in [rlgl] module and can be changed there
#define MAX_BATCH_ELEMENTS 8192

Missing FFI functions

Hi! I've tried to play with the project a bit, but I don't manage to get the script to run. I get this error:

julik@jet <redacted> $ ruby window.rb 
/Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/library.rb:216:in `attach_function': Function 'DrawLineBezierQuad' not found in [libraylib.dylib] (FFI::NotFoundError)
	from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib/core/functions.rb:582:in `<module:Raylib>'
	from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib/core/functions.rb:1:in `<top (required)>'
	from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
	from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
	from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib/core.rb:5:in `<top (required)>'
	from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
	from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
	from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib.rb:12:in `<top (required)>'
	from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:141:in `require'
	from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:141:in `rescue in require'
	from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:135:in `require'
	from window.rb:1:in `<main>

I've looked for the function in the raylib GH repo but it doesn't show anywhere. Could it be that the FFI bindings need to be regenerated from time to time?

Ruby is

julik@jet banksvc (main) $ ruby -v
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-darwin21]

and this is macOS Monterey (10.12) and raylib is installed using brew (brew install raylib)

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.