{"id":24072949,"url":"https://github.com/markusmoenig/metalray","last_synced_at":"2025-06-23T12:33:55.990Z","repository":{"id":189725446,"uuid":"681080222","full_name":"markusmoenig/metalRay","owner":"markusmoenig","description":"Code games in Swift and C in this \"down to the metal\" game framework for Xcode","archived":false,"fork":false,"pushed_at":"2023-08-31T08:29:36.000Z","size":1095,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-28T15:46:33.359Z","etag":null,"topics":["game-development","game-engine","ios","macos","metal","raylib","swift","tvos","xcode"],"latest_commit_sha":null,"homepage":"https://moenig.io","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markusmoenig.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"markusmoenig","patreon":"markusmoenig"}},"created_at":"2023-08-21T08:11:27.000Z","updated_at":"2025-02-06T00:34:44.000Z","dependencies_parsed_at":"2025-04-28T15:37:16.834Z","dependency_job_id":"f4176d32-2a08-430f-b6ed-1c1a1f53477c","html_url":"https://github.com/markusmoenig/metalRay","commit_stats":null,"previous_names":["markusmoenig/metalray"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/markusmoenig/metalRay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FmetalRay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FmetalRay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FmetalRay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FmetalRay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markusmoenig","download_url":"https://codeload.github.com/markusmoenig/metalRay/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FmetalRay/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261479447,"owners_count":23164693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game-development","game-engine","ios","macos","metal","raylib","swift","tvos","xcode"],"created_at":"2025-01-09T17:24:06.270Z","updated_at":"2025-06-23T12:33:50.964Z","avatar_url":"https://github.com/markusmoenig.png","language":"Swift","funding_links":["https://github.com/sponsors/markusmoenig","https://patreon.com/markusmoenig"],"categories":[],"sub_categories":[],"readme":"\n## metalRay\n\n**metalRay** is a bare bones game framework for the Apple ecosystem. If you want to code games close to the Metal with a convenient API (in the tradition of frameworks like [raylib](https://raylib.com))  you will feel right at home.\n\nYou can write games in Swift and in C directly in Xcode while being able to create C style interoperable memory structures and pass them to your Metal shaders.\n\n*metalRay* focuses right now on 2D drawing, 3D support will be integrated once 2D is stable.\n\n## Features\n\n* Use drawing functions, textures and shaders with an easy to use API.\n* Share memory (C style structs) between Swift, C and Metal.\n* System device events can be easily queried in the game update functions.\n* Draw text using SDF textures.\n* Support for 2D physics and Tiled are incoming.\n* Games / Apps can be deployed easily to macOS, iOS and tvOS using Xcode.\n\n## Why ?\n\nI like to write games low level, and all the popular convenience frameworks out there (SDL2, raylib etc.) are not based on Metal but OpenGL, which makes iOS and tvOS compatibility problematic.\n\nAnd being nostalgic, I also really enjoy coding in C again sometimes. Especially for implementing some of the classics. Get your hands dirty!\n\nBeing able to deploy your games easily to macOS, iOS and tvOS is a major advantage compared to the mostly limited cross-platform alternatives.\n\n#### Downsides\n\n* The API is implemented in Swift, however with a C style calling convention to make it work in both Swift and C. So no swiftiniess and functions return -1 if something goes wrong (and not null). Texts are passed as C Strings (use *toCStr()* to convert Strings to C strings).\n* While it is super convenient to code your game directly in Xcode, the downside is that merging your fork of this repo can be a bit tedious (when updated). Basically keep your files limited to the *Game* folder and merge everything outside the *Game* folder (Swift, C, Metal, .h) files.\n\n## How to use\n\nFork this repository and open the Xcode project. All game related functions are inside the **Game** folder\n\n* **game.swift**. The Swift based game entry point. Use the initGame(), updateGame() and deinitGame() functons.\n\n* **game.c** The corresponding C file with InitGame(), UpdateGame() and DeinitGame().\n\n* **header.h**. Implement C like structures here. These structures can be used in Swift and C as well as in Metal.\n\nBy default the Swift functions are called. If you want to implement (or mix) with the C code, call the C functions from there. See the example default code.\n\nPlace all your resources somewhere in the *Game* folder.\n\nThe Xcode project contains targets for macOS, iOS and tvOS.\n\nI will soon add some Swift and C examples to the project.\n\n## Status\n\n- [x] Render Targets\n- [x] Textures\n- [x] Rectangle Drawing\n- [x] SDF Text Drawing\n- [x] Input Events Partially implemented (macOS, iOS, tvOS)\n- [ ] SDF based Shapes\n- [ ] Custom Shaders\n- [ ] 2D Physics\n- [ ] Tiled Import\n- [ ] 3D Support\n\n---\n\n## Structures used in the API\n\nLoaned from raylib.\n\n```c\n// Color, 4 components, R8G8B8A8 (32bit)\ntypedef struct Color {\n    unsigned char r;        // Color red value\n    unsigned char g;        // Color green value\n    unsigned char b;        // Color blue value\n    unsigned char a;        // Color alpha value\n} Color;\n\n// Vector2, 2 components\ntypedef struct Vector2 {\n    float x;                // Vector x component\n    float y;                // Vector y component\n} Vector2;\n\n// Vector3, 3 components\ntypedef struct Vector3 {\n    float x;                // Vector x component\n    float y;                // Vector y component\n    float z;                // Vector z component\n} Vector3;\n\n// Vector4, 4 components\ntypedef struct Vector4 {\n    float x;                // Vector x component\n    float y;                // Vector y component\n    float z;                // Vector z component\n    float w;                // Vector w component\n} Vector4;\n\n// Rectangle, 4 components\ntypedef struct Rectangle {\n    float x;                // Rectangle top-left corner position x\n    float y;                // Rectangle top-left corner position y\n    float width;            // Rectangle width\n    float height;           // Rectangle height\n} Rectangle;\n```\n\nThese structures are used in the API and can be created from both Swift and C and passed to Metal shaders.\n\n---\n\n## Window / Events\n\n```swift\n// Returns the size of the screen / device\nGetScreenSize() -\u003e Vector2;\n\n// Left mouse click or touch event\nHasTap() -\u003e Bool;\n\n// Left mouse double click or double touch event\nHasDoubleTap() -\u003e Bool;\n\n// Left mouse is down or ongoing touch event\nHasTouch() -\u003e Bool;\n\n// Left mouse up or touch up event\nHasTouchEnded() -\u003e Bool;\n\n// Current mouse or touch event position in window / device\nGetTouchPos() -\u003e Vector2;\n```\n\n## Drawing\n\n```swift\n// Starts drawing, if you change the render target you need to end drawing to your current target first.\nBeginDrawing();\n// End drawing\nEndDrawing();\n\n// Sets the current font\nSetFont(name: CString);\n// Returns the size of the given text\nGetTextSize(text: CString, size: Float) -\u003e Vector2\n// Draws the text of the given size at the given position\nDrawText(pos: Vector2, text: CString, size: Float, color: Color);\n\n// Clears the current render target in the given color\nClear(color: Color);\n// Draws a rectangle of the given color\nDrawRect(rect: Rectangle, color: Color);\n// Draws a rotated (around its center) rectangle of the given color\nDrawRectRotCenter(rect: Rectangle, color: Color, rot: Int);\n// More to come\n```\n\n## Textures\n\n```swift\n// Creates an RGBA8 texture of the given width and height and returns its id. Returns -1 if unsuccessful.\nCreateTexture(width: Int, height: Int) -\u003e Int;\n// Load an image in the Xcode project into a texture and returns its id. Returns -1 if unsuccessful.\nLoadTexture(name: CString) -\u003e Int;\n\n// Makes the texture of the given id the new render target. Use 0 to switch back to the default viewport. Make sure to end and restart drawing.\nSetTarget(id: Int) -\u003e Bool;\n\n// Makes the texture of the given id the new texture. All drawing functions will replace the color value with the interpolated texture value. Use 0 to disable texture support (needs to be called before EndDrawing() too).\nSetTexture(id: Int) -\u003e Bool;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusmoenig%2Fmetalray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkusmoenig%2Fmetalray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusmoenig%2Fmetalray/lists"}