A Swift package for Raylib. Builds Raylib from source so no need to fiddle with libraries.

Related tags

Games Raylib
Overview

Raylib for Swift

Windows macOS Linux

Twitter YouTube Reddit Discord

This package brings Raylib to Swift.

Setup

Raylib for Swift uses Swift's C interoperability and compiler to build Raylib from source code. So there's no setup required, just add the package as a dependency and start making games!

.package(url: "https://github.com/STREGAsGate/Raylib.git", .branch("master"))

On Windows and macOS you only need Swift. For linux, see install required libraries.

Swifty

Original global functions are now static members of the Raylib type.

Raylib.initWindow(screenWidth, screenheight, "My First Raylib Window!")

To Do

It's a goal of this project to have all the global functions available on their respective types as members.

As an example Image, now has new initializers.

let image = Image(color: .green, width: 256, height: 256)

Doing this for the entire API will increase discoverability and make Raylib for Swift a more Swifty experience.


Official Readme

raylib is a simple and easy-to-use library to enjoy videogames programming.

raylib is highly inspired by Borland BGI graphics lib and by XNA framework and it's specially well suited for prototyping, tooling, graphical applications, embedded systems and education.

NOTE for ADVENTURERS: raylib is a programming library to enjoy videogames programming; no fancy interface, no visual helpers, no auto-debugging... just coding in the most pure spartan-programmers way.

Ready to learn? Jump to code examples!



GitHub contributors GitHub All Releases GitHub commits since tagged version License

Chat on Discord GitHub stars Twitter Follow Subreddit subscribers

Windows Linux macOS Android WebAssembly

CMakeBuilds Windows Examples Linux Examples

features

  • NO external dependencies, all required libraries are bundled into raylib
  • Multiple platforms supported: Windows, Linux, MacOS, RPI, Android, HTML5... and more!
  • Written in plain C code (C99) in PascalCase/camelCase notation
  • Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES 2.0)
  • Unique OpenGL abstraction layer (usable as standalone module): rlgl
  • Multiple Fonts formats supported (TTF, XNA 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, glTF)
  • 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 +120 code examples!
  • Bindings to +50 programming languages!
  • Free and open source.

raylib uses internally some libraries for window/graphics/inputs management and also to support different fileformats loading, all those libraries are embedded with raylib and are available in src/external directory. Check raylib dependencies on raylib Wiki for a detailed list.

basic example

This is a basic raylib example, it creates a window and it draws the text "Congrats! You created your first window!" in the middle of the screen. Check this example running live on web here.

#include "raylib.h"

int main(void)
{
    InitWindow(800, 450, "raylib [core] example - basic window");

    while (!WindowShouldClose())
    {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }

    CloseWindow();

    return 0;
}

build and installation

raylib binary releases for Windows, Linux and macOS are available at the Github Releases page.

raylib is also available via multiple package managers on multiple OS distributions.

Installing and building raylib via vcpkg

You can download and install raylib using the vcpkg dependency manager:

  git clone https://github.com/Microsoft/vcpkg.git
  cd vcpkg
  ./bootstrap-vcpkg.sh
  ./vcpkg integrate install
  vcpkg install raylib

The raylib port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Installing and building raylib via conan

You can download and install raylib using the conan dependency manager:

  https://docs.conan.io/en/latest/getting_started.html

The raylib recipe in conan is kept up to date by conan team members and community contributors. If the version is out of date, please create an issue or pull request on the conan-center-index repository.

Installing and building raylib on multiple platforms

raylib Wiki contains detailed instructions on building and usage on multiple platforms.

Note that Wiki is open for edit, if you find some issue while building raylib for your target platform, feel free to edit the Wiki or open and issue related to it.

Setup raylib with multiple IDEs

raylib has been developed on Windows platform using Notepad++ and MinGW GCC compiler but it can be used with other IDEs on multiple platforms.

Projects directory contains several ready-to-use project templates to build raylib and code examples with multiple IDEs.

Note that there are lots of IDEs supported, some of the provided templates could require some review, please, if you find some issue with some template or you think they could be improved, feel free to send a PR or open a related issue.

learning and docs

raylib is designed to be learned using the examples as the main reference. There is no standard API documentation but there is a cheatsheet containing all the functions available on the library and a short description of each one of them, input parameters and result value names should be intuitive enough to understand how each function works.

Some additional documentation about raylib design can be found in raylib GitHub Wiki. Here the more relevant links:

contact and networks

raylib is present in several networks and raylib community is growing everyday. If you are using raylib and enjoying it, feel free to join us in any of these networks. The most active network is our Discord server! :)

license

raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.

Comments
  • Update to v4

    Update to v4

    Hello, I've spent some time updating the package to a more recent commit of Raylib, at version 4. There is a couple of commented functions because I'm not sure what's the new version of them.

    I wanted to ask, do you have any automated process to do this or is all done manually?

    opened by alexito4 3
  • Updated the README with a section for how to create a new project.

    Updated the README with a section for how to create a new project.

    I also added various links and had fun making the example project respond to mouse events. I really wanted to also delete the old Raylib README contents, but I figured you probably left it in there for a reason, so I didn't.

    documentation 
    opened by mgrider 2
  • Please indicate that `.branch(

    Please indicate that `.branch("master")` is necessary to avoid a build error regarding unsafe build flags for Raylib and GLFW

    Hello! Thank you very much for creating this Swift package to streamline working with Raylib.

    While testing out your library, I tried using from: "4.0.0" for the package and encountered this error:

    error: the target '_RaylibC' in product 'Raylib' contains unsafe build flags
    

    Then I discovered this thread regarding the use of .unsafeFlags() and .branch() / from - https://forums.swift.org/t/question-about-contains-unsafe-build-flags-in-spm/47677

    I understand that since your library needs to use .unsafeFlags() to compile Raylib and GLFW together via clang -x objective-c -fno-obj-arc, could you please document that users of this library must use .branch("master")?

    opened by willowell 1
  • package definition xcode

    package definition xcode

    I was able to get this running in xcode 13.1, but I had to modify the package file slightly.

    I had to modify the package and target thusly:

    ` .package(name: "Raylib", url: "https://github.com/STREGAsGate/Raylib.git", .branch("master"))

    ... .target( name: "", dependencies: ["Raylib"]), `

    without this, I would receive the error "No such module 'Raylib'" when I tried to import "Raylib" in my swift files. Not sure if it's an update with newer versions of Swift or not.

    This is a fantastic project. Thanks for putting this work together.

    opened by madamc 1
  • Load default character set with LoadFontEx

    Load default character set with LoadFontEx

    Raylib allows loading of the default character set with LoadFontEx by setting fontChars to null.

    This fix should allow for the same behavior when using the bindings.

    opened by xiroV 0
  • rlLoadTexture  EXC_BAD_ACCESS

    rlLoadTexture EXC_BAD_ACCESS

    Hello! It's most likely I'm doing something wrong...

    Let's say I'm trying to load image: public var fish1 = Raylib.loadImage(Bundle.module.path(forResource: "fish1", ofType: "png", inDirectory: "Resources") ?? "") And it's loaded successfully (output from terminal): File loaded successfully INFO: IMAGE: Data loaded successfully (256x256 | R8G8B8A8 | 1 mipmaps)

    But then I'm trying to load texture: public var fishTexture1 = Raylib.loadTextureFromImage(fish1) And it bring back to _Sources/RaylibC/UnmodifiedRaylibCSrc/rlgl and rlLoadTexture (line number 2688) with EXC_BAD_ACCESS Thanks in advance for your help!

    opened by GothStar 0
  • Migrate to Raylib 4.2

    Migrate to Raylib 4.2

    Took a pass at updating to use the newly released version 4.2 of Raylib. I'm working on adding several of the Raylib extras libraries such as rres as separate products in the Package. I'll submit them in a later PR.

    opened by XeresRazor 1
  • Shader example?

    Shader example?

    The shader stuff appears to be wrapped but it silently halts the program for me when I try to load one:

    let rscFS = "/home/arckex/Raylib/Sources/Example/resources/shaders/glsl330/bloom.fs"
    let rscFSTXT = try String(contentsOfFile: rscFS)
    let rscVS = "/home/arckex/Raylib/Sources/Example/resources/shaders/glsl330/base.vs"
    let rscVSTXT = try String(contentsOfFile: rscVS)
    let shader = Raylib.loadShaderFromMemory(rscVSTXT, rscFSTXT)
    

    Can you make a min example of loading a shader? Thanks so much

    documentation help wanted good first issue 
    opened by andymule 1
Releases(v4.0.0)
Owner
Strega's Gate
I'm Dustin, a solo Indie Game Developer. I code my games from scratch and do my own art.
Strega's Gate
Open source release of Canabalt for iOS

Open source release of Canabalt for iOS

Eric Johnson 1.6k Dec 31, 2022
DOOM Classic for iOS Source Release

DOOM Classic iOS v2.1 GPL source release =============================================== This file contains the following sections: GENERAL NOTES LI

id Software 735 Dec 22, 2022
DropColour - Open-Source Arcade Game for iOS

DropColour - Open-Source Arcade Game for iOS iOS project written in Swift 3.1 during several hackathons at EL Passion. DropColour is an arcade game in

EL Passion 175 Jan 3, 2023
The one and only open source 4X MMO mid-core strategy game for iOS. Similar to Game of War and Mobile Strike

4X MMO Strategy Game for iOS I have spent 4 years of my life and a significant amount of money into completing this game and I hope you enjoy it. For

shankqr 69 Nov 16, 2022
Open Source Real Time Strategy game based on Warfare Incorporated

About Hostile Takeover is the open source release of the wildly popular mobile Real Time Strategy game Warfare Incorporated. Warfare Incorporated's de

Spiffcode 168 Nov 2, 2022
Open Source release of the code for the iOS retro 80s platform game Loot Raider

Loot Raider iOS v1.7 (c) 2018 Infusions of Grandeur - Written By: Eric Crichlow Background Loot Raider is the "spiritual successor" to a game named "G

Eric Crichlow 9 Feb 9, 2022
Swift-WordleSolver - Solve and analyze Wordle games. Command-line tool written in Swift

Swift-WordleSolver - Solve and analyze Wordle games. Command-line tool written in Swift

Tobi Schweiger 0 Jan 26, 2022
Imagine Engine - a fast, high performance Swift 2D game engine for Apple's platforms

Welcome to Imagine Engine, an ongoing project that aims to create a fast, high performance Swift 2D game engine for Apple's platforms that is also a j

John Sundell 1.8k Jan 3, 2023
Sage is a cross-platform chess library for Swift.

Sage is not a chess engine; it's a move generator. Hexe, on the other hand, is able to both generate moves and evaluate them.

Nikolai Vazquez 368 Dec 29, 2022
🐦 Flappy Bird reincarnation [Swift 5.3, GameplayKit, SpriteKit, iOS 12].

?? Flappy Bird reincarnation [Swift 5.3, GameplayKit, SpriteKit, iOS 12].

Astemir Eleev 290 Dec 27, 2022
A game engine built with SDL and Swift.

Lark A game engine made with Swift and SDL. This is a pre-alpha work-in-progress. Don't try to use this unless you really know what you're doing. I ba

June Bash 41 Mar 11, 2022
2048 for Swift

swift-2048 A working port of iOS-2048 to Apple's new Swift language. Like the original Objective-C version, swift-2048 does not rely upon SpriteKit. S

Austin Zheng 3.1k Dec 27, 2022
A simple Chess game for iOS, written in Swift

Swift Chess This is a simple chess game for iPhone and iPad, designed for novice players. It features a very simple AI that plays much like a beginner

Nick Lockwood 135 Jan 6, 2023
swift implementation of flappy bird. More at fullstackedu.com

FlappySwift An implementation of Flappy Bird in Swift for iOS 8. Notes We're launching a course Game Programming with Swift If you are interested in e

newline (formerly Fullstack.io) 9.5k Dec 29, 2022
iOS Swift Game - Push SpriteKit to the limit

iOS Swift Project - Legend Wings - EverWing's Mini Clone EverWing is a popular action game. Survive as much you can, earn gold, and upgrade/purchase n

Wong Guan 512 Dec 20, 2022
Simple memory game written in Swift 4 using VIPER Architecture.

Viper Memory Game Simple memory game written in Swift 4.2 using VIPER Architecture. The Memory Game is a deck of cards where the user needs to find ma

Mati 23 Jun 6, 2022
A project introducing you to Swift

?? My first Memory ?? ?? An introduction to iOS development with Swift. A memory game implementation fetching images from Instagram. This project aims

Alexander Cyon 72 Sep 5, 2022
2D ECS game engine in 100% Swift + SwiftUI for iOS, macOS, tvOS

OctopusKit A 2D game engine based on ECS and written in 100% Swift for iOS, macOS and tvOS. If you've tried making a game in Swift while sticking to t

null 335 Dec 12, 2022
Letter Quiz game with swift for ios

LETTERQUIZ Title: LetterQuiz Category: Game Genre: Trivia, Puzzle, Quiz Platform: IOS Language: Swift 4.0 Available at: Developer: Martin Bruland Crea

Martin Bruland 1 Nov 25, 2022