Code Monkey home page Code Monkey logo

rayex's Introduction

Rayex

Hex.pm API Docs Run Tests

Twitter

Rayex provides Elixir NIF bindings to Raylib

WIP: many of the functions on raylib are yet not implemented, check the contributing section to help

Installation

The package can be installed by adding rayex to your list of dependencies in mix.exs:

def deps do
  [
    {:rayex, "~> 0.0.2"}
  ]
end

The docs can be found at https://hexdocs.pm/rayex.

Running from source

You need the following packages installed on your system:

  • elixir
  • erlang (headers)
  • pkg-config
  • raylib v4.2
  • glibc
  • clang-tools (formatter)

If you are using Nix or NixOS you can run nix develop to get an ready to go env to work with!

Now you can run:

mix deps.get
iex -S mix

And test with:

# Import all modules
iex> use Rayex

# open new window
iex> init_window(200, 200, "window name")

# draw a line
iex> begin_drawing()
iex> draw_line(10, 10, 50, 51, %{r: 255, g: 161, b: 0, a: 255})
iex> end_drawing()

You can also run our examples!!

cd examples/3d_picking/
mix deps.gen
iex -S mix
iex> The3dPicking.run()

Contributing

There are a few things that you need to know about the code:

  • This project aims to run each one of those functions with elixir
  • To do so, we are using Unifex to create NIFs
  • On c_src/rayex/rayex.spec.exs you can find the definitions that will be generated by Unifex
  • On c_src/rayex/rayex.c you can find how they are implemented
  • On c_src/rayex/rayex.h and lib/unifex/code_generator/base_types/... you can find custom types
  • On lib/rayex/unifex/raylib.ex is where the generated functions will be stored and used for each module under lib/rayex, the public API

Any contributions are appreciated

License

Copyright 2021 Shiryel

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

rayex's People

Contributors

shiryel avatar rafaelrc7 avatar

Stargazers

Rico Moorman avatar  avatar  avatar Mathew Garland avatar  avatar Łukasz Skotarek avatar David Cao avatar Dwi Prihandi avatar Guilhem Bernard avatar  avatar Raúl Chouza  avatar  avatar Samuel Fontes da Silva avatar g_kenkun avatar Noah Betzen avatar  avatar Maxsuel Fernandes Maccari avatar Bruno Antunes avatar Mayeu avatar Paulo Sergio avatar  avatar MiniApple avatar Rodrigo Fernandes avatar Alfred Reinold Baudisch avatar Dorian Iacobescu avatar Igor Fernandes avatar  avatar Gan Jun Kai avatar Marcus Kruse avatar Fabio Petrucci avatar hsc avatar drew avatar Maximilian Schulz avatar Craig Read avatar Cristian Molina avatar Lachlan Wilger avatar a~ avatar Frank Taylor avatar Seif avatar Nathan Fritch avatar Thomas Lackner avatar

Watchers

 avatar  avatar a~ avatar  avatar

rayex's Issues

Dialyzer complaining about broken contract.

In the following code snippet

  def main_loop() do
    Rayex.Core.clear_background(%Color{r: 255, g: 255, b: 255, a: 255})

    Rayex.Core.begin_drawing()

    Rayex.Shapes.draw_triangle(
      %Vector2{x: @screen_width / 4.0 * 3.0, y: 80.0},
      %Vector2{x: @screen_width / 4.0 * 3.0 - 60.0, y: 150.0},
      %Vector2{x: @screen_width / 4.0 * 3.0 + 60.0, y: 150.0},
      %Color{r: 128, g: 0, b: 128, a: 255}
    )

    Rayex.Core.end_drawing()
    main_loop()
  end

Dialyzer complains when i pass in 0 as the value for g in the Rayex.Structs.Color struct. I believe the cause is that it expects a positive integer, which 0 is not.
The warning goes away once i pass in any integer above 0.

Any ideas how i can go about using 0 without the dialyzer complaining?

init_window/3 hangs and doesn't open a window on MacOS

Hi,

Awesome project! Would love to make some games using Elixir.

However, when I try to run the example (or even just run Rayex.Core.init_window/3 in iex) it hangs indefinitely and doesn't open a window or do anything else as far as I can tell. By using a local version of raylib and adding a bunch of log statements, I'm able to pin down the problem to this line in GLFW:

    if (![[NSRunningApplication currentApplication] isFinishedLaunching])
        [NSApp run];

https://github.com/raysan5/raylib/blob/master/src/external/glfw/src/cocoa_init.m#L555

(Note this is on MacOS, hence the objective-C.) It's the [NSApp run] call that seems to just hang forever. I tried removing that line but I get a completely different error that makes it seem like that line probably shouldn't be removed. And I'm guessing that there's a better solution than fiddling around with the GLFW sources, since it wouldn't be ideal to have to use a fork of GLFW just for this one project.

Any ideas what could be going wrong here? Has anyone else been able to get this running on mac?

System details:

macOS Big Sur 11.6.1
elixir 1.12
erlang 24.1.7

Note -- the problem isn't Raylib or GLFW, since I'm able to compile and run the basic Raylib example with C.

Compilation issue

Hi! Trying to get Rayex working locally and I keep getting this error, no matter what I try

Bundlex: Building natives: rayex
Package raylib was not found in the pkg-config search path.
Perhaps you should add the directory containing `raylib.pc'
to the PKG_CONFIG_PATH environment variable
Package 'raylib', required by 'virtual:world', not found
** (MatchError) no match of right hand side value: {"", 1}
    (bundlex 1.0.0) lib/bundlex/toolchain/common/unix.ex:111: Bundlex.Toolchain.Common.Unix.pkg_config/2
    (bundlex 1.0.0) lib/bundlex/toolchain/common/unix.ex:17: Bundlex.Toolchain.Common.Unix.compiler_commands/5
    (bundlex 1.0.0) lib/bundlex/native.ex:107: Bundlex.Native.resolve_native/4
    (bunch 1.4.1) lib/bunch/enum.ex:244: Bunch.Enum.do_try_flat_map/3
    (bundlex 1.0.0) lib/tasks/compile.bundlex.ex:40: Mix.Tasks.Compile.Bundlex.run/1
    (mix 1.15.7) lib/mix/task.ex:455: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.15.7) lib/mix/tasks/compile.all.ex:124: Mix.Tasks.Compile.All.run_compiler/2
    (mix 1.15.7) lib/mix/tasks/compile.all.ex:104: Mix.Tasks.Compile.All.compile/4

I've got PKG_CONFIG_PATH and LD_CONFIG_PATH set (I think?) have you seen this before?

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.