An open API service indexing awesome lists of open source software.

https://github.com/greenfork/nimraylib_now

The Ultimate Raylib gaming library wrapper for Nim
https://github.com/greenfork/nimraylib_now

Last synced: about 1 year ago
JSON representation

The Ultimate Raylib gaming library wrapper for Nim

Awesome Lists containing this project

README

          

# End of life

The project will no longer be maintained. Reasons:

- I personally don't do any game development for some time now.

- The approach of automatic bindings generation was very new and easy to
maintain. Unfortunately as the Nim language progresses, it adds a lot of
features that help with automatic memory management, boundary detection and
other quality of life things. It is not feasible to automatically generate
these things, so the whole approach doesn't look very lucrative to continue
with. Proper Nim bindings will require lots of manual code to accomodate all
the fascinating language features.

The successor bindings can be considered ,
feel free to take a look at them! Other projects can also emerge but as of
2023-04-15 these bindings look like the most promising ones.

Feel free to fork this repository and do anything with the code, happy hacking!

# NimraylibNow! - The Ultimate Raylib wrapper for Nim

The most idiomatic and up-to-date wrapper for [Raylib] gaming C library.
Use this library if you want to write games using [Raylib] in [Nim].

This library is an effort to create an automatically generated wrapper which can
be easily upgraded to any future version of [Raylib]. Anyone should be able to
upgrade it with some effort and [HACKING](HACKING.md) should be a guide on how
to do it. Please file a bug report if any of that is too far from the reality.

[Nim]: https://nim-lang.org/

## Features

* Automated generation of the wrapper using the power of (((Nim)))

* Idiomatic Nim naming and conventions so you write **Nim** code, not C

* 60+ [examples](examples/) converted from C to Nim

* Includes modules: [raylib], [raymath], [rlgl], [raygui], [physac]

* Supports Windows, Linux, MacOS, Emscripten (see [Emscripten example])

* Supports static compilation, dynamic linking - you choose

[raylib]: https://github.com/raysan5/raylib
[raymath]: https://github.com/raysan5/raylib/blob/master/src/raymath.h
[rlgl]: https://github.com/raysan5/raylib/blob/master/src/rlgl.h
[raygui]: https://github.com/raysan5/raygui
[physac]: https://github.com/raysan5/raylib/blob/master/src/physac.h
[Emscripten example]: examples/emscripten/

## Quickstart

1. Install NimraylibNow!
```shell
$ nimble install nimraylib_now # wait 10 minutes for download, sorry
```
2. Copy any example to your file, for instance [crown.nim](examples/original/crown.nim)
3. Compile and run it:
```shell
$ nim c -r -d:release --gc:orc crown.nim
```

Explanation of flags:
- `-r` - run after compiling
- `-d:release` - for speed, but also cuts away debugging information
- `--gc:orc` - memory management without garbage collection and
with better C interoperability

## Current version and upgrading from previous versions

NimraylibNow! v0.15 is a wrapper for [Raylib v4.2.0] and [Raygui v3.2] and works
for Nim v1.4.2+.

See [CHANGELOG](CHANGELOG.md) for any tips on how to upgrade your code
from previous versions.

[Raylib v4.2.0]: https://github.com/raysan5/raylib/releases/tag/4.2.0
[Raygui v3.2]: https://github.com/raysan5/raygui/releases/tag/3.2

## Install NimraylibNow!

Install this library with nimble (takes **6-10(!) minutes** because of huge
original raylib repository):
```shell
$ nimble install nimraylib_now
```

Or put it into your `.nimble` file:
```nim
requires "nimraylib_now"
```

## How to use NimraylibNow!

Import any necessary modules and use it:

```nim
# Import everything but rlgl, should be enough for most cases!
import nimraylib_now

# Import only necessary modules for more granularity
import nimraylib_now/raylib
import nimraylib_now/[raylib, raymath, raygui]
from nimraylib_now/rlgl as rl import nil # import rlgl with a mandatory prefix rl
```

See [examples](examples/) for how to use it.
You should generally be able to follow any tutorials for official C bindings,
just mind the [naming](#naming-differences-with-c). Also see official
[cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html) and
directly inspect the binding sources, e.g. for
[raylib](src/nimraylib_now/not_mangled/raylib.nim).

Here is a long example to showcase most features
([crown.nim](examples/original/crown.nim)).

```nim
import math
import nimraylib_now

const
nimFg: Color = (0xff, 0xc2, 0x00) # Use this shortcut with alpha = 255!
nimBg: Color = (0x17, 0x18, 0x1f)

# Let's draw a Nim crown!
const
crownSides = 8 # Low-polygon version
centerAngle = 2.0 * PI / crownSides.float # Angle from the center of a circle
lowerRadius = 2.0 # Lower crown circle
upperRadius = lowerRadius * 1.4 # Upper crown circle
mainHeight = lowerRadius * 0.8 # Height without teeth
toothHeight = mainHeight * 1.3 # Height with teeth
toothSkew = 1.2 # Little angle for teeth

var
lowerPoints, upperPoints: array[crownSides, tuple[x, y: float]]

# Get evenly spaced points on the lower and upper circles,
# use Nim's math module for that
for i in 0..