{"id":17424141,"url":"https://github.com/ctreffs/swiftsdl2","last_synced_at":"2025-04-05T10:09:09.902Z","repository":{"id":43144325,"uuid":"219311342","full_name":"ctreffs/SwiftSDL2","owner":"ctreffs","description":"Swift wrapper around Simple Direct Media Layer (SDL2) for macOS, iOS, Linux and Windows","archived":false,"fork":false,"pushed_at":"2024-10-23T17:02:29.000Z","size":2859,"stargazers_count":107,"open_issues_count":5,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-24T18:16:02.755Z","etag":null,"topics":["linux","macos","sdl","sdl2","simple-direct-media-layer","spm","swift","swift-package-manager","windows","zlib"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctreffs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["ctreffs"],"custom":["https://www.paypal.com/donate?hosted_button_id=GCG3K54SKRALQ"]}},"created_at":"2019-11-03T14:13:37.000Z","updated_at":"2024-10-20T07:00:16.000Z","dependencies_parsed_at":"2023-09-26T21:35:18.618Z","dependency_job_id":"af4754db-17b0-4e07-a48d-dedd69c1dcfb","html_url":"https://github.com/ctreffs/SwiftSDL2","commit_stats":{"total_commits":57,"total_committers":3,"mean_commits":19.0,"dds":0.1578947368421053,"last_synced_commit":"df30583c88c8bb7bccaf8875f0ec4a39cb149fba"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctreffs%2FSwiftSDL2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctreffs%2FSwiftSDL2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctreffs%2FSwiftSDL2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctreffs%2FSwiftSDL2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctreffs","download_url":"https://codeload.github.com/ctreffs/SwiftSDL2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318745,"owners_count":20919484,"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":["linux","macos","sdl","sdl2","simple-direct-media-layer","spm","swift","swift-package-manager","windows","zlib"],"created_at":"2024-10-17T05:06:18.426Z","updated_at":"2025-04-05T10:09:09.878Z","avatar_url":"https://github.com/ctreffs.png","language":"C","funding_links":["https://github.com/sponsors/ctreffs","https://www.paypal.com/donate?hosted_button_id=GCG3K54SKRALQ"],"categories":[],"sub_categories":[],"readme":"\n# \u003cimg src=\"https://www.libsdl.org/media/SDL_logo.png\" height=\"20\" max-width=\"90%\" alt=\"SDL2\" /\u003e Swift SDL2\n\n[![license](https://img.shields.io/badge/license-zlib-brightgreen.svg)](LICENSE)\n[![Linux](https://github.com/ctreffs/SwiftSDL2/actions/workflows/ci-linux.yml/badge.svg)](https://github.com/ctreffs/SwiftSDL2/actions/workflows/ci-linux.yml)\n[![macOS](https://github.com/ctreffs/SwiftSDL2/actions/workflows/ci-macos.yml/badge.svg)](https://github.com/ctreffs/SwiftSDL2/actions/workflows/ci-macos.yml)\n[![Windows](https://github.com/ctreffs/SwiftSDL2/actions/workflows/ci-windows.yml/badge.svg)](https://github.com/ctreffs/SwiftSDL2/actions/workflows/ci-windows.yml)\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fctreffs%2FSwiftSDL2%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/ctreffs/SwiftSDL2)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fctreffs%2FSwiftSDL2%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/ctreffs/SwiftSDL2)\n\nThis is a  **thin** Swift wrapper around the popular and excellent [**Simple DirectMedia Layer**](https://www.libsdl.org) library.  \nIt provides a **swifty** and **typesafe** API. \n\n\u003e Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve's award winning catalog and many Humble Bundle games.\n\u003e SDL officially supports Windows, Mac OS X, Linux, iOS, and Android. Support for other platforms may be found in the source code.\n\u003e SDL is written in C, works natively with C++, and there are bindings available for several other languages, including C# and Python.   \n\u003e ~ [www.libsdl.org](https://www.libsdl.org)\n\n## 🚀 Getting Started\n\nThese instructions will get your copy of the project up and running on your local machine and provide a code example.\n\n### 📋 Prerequisites\n\n* [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager)\n* [Swiftlint](https://github.com/realm/SwiftLint) for linting - (optional)\n\n### 💻 Installing\n\nSwift SDL2 is available for all platforms that support [Swift 5.6](https://swift.org/) and higher and the [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager).\n\nExtend the following lines in your `Package.swift` file or use it to create a new project.\n\n```swift\n// swift-tools-version:5.6\n\nimport PackageDescription\n\nlet package = Package(\n    name: \"YourPackageName\",\n    dependencies: [\n        .package(url: \"https://github.com/ctreffs/SwiftSDL2.git\", from: \"1.4.0\")\n    ],\n    targets: [\n        .target(\n            name: \"YourTargetName\",\n            dependencies: [\n                .product(name: \"SDL\", package: \"SwiftSDL2\")\n            ])\n    ]\n)\n\n```\nDepending on your platform several extra steps have to be taken to SDL2 to compile.\n\n### Apple\n\nFor Apple platforms (macOS, iOS, tvOS) SDL2 is provided using an XCFramework so mo extra steps are needed.\n\n### Linux\n\nOn Linux platforms you are required to use the following command to install SDL2 as a system package:\n\n```sh\napt-get install libsdl2-dev\n```\n\n### Windows\n\nSince Windows is a fairly new platform for Swift development there are some manual steps to perform before you can use the package.\nAll the following steps assume you have a working swift environment on your Windows machine.\nIf not follow the [instructions on how to install Swift on Windows](https://www.swift.org/download/#windows).\n\nYou can quickly test this package is working by running the `./buildPackageWin.ps1` powershell script.\n\n## 📝 Code Example\n\n### Minimal\n\nA minimal example is located at [Sources/Demos/Minimal](Sources/Demos/Minimal).   \n\n```swift\nimport SDL\n\n// Initialize SDL video systems\nguard SDL_Init(SDL_INIT_VIDEO) == 0 else {\n    fatalError(\"SDL could not initialize! SDL_Error: \\(String(cString: SDL_GetError()))\")\n}\n\n// Create a window at the center of the screen with 800x600 pixel resolution\nlet window = SDL_CreateWindow(\n    \"SDL2 Minimal Demo\",\n    Int32(SDL_WINDOWPOS_CENTERED_MASK), Int32(SDL_WINDOWPOS_CENTERED_MASK),\n    800, 600,\n    SDL_WINDOW_SHOWN.rawValue)\n\nvar quit = false\nvar event = SDL_Event()\n\n// Run until app is quit\nwhile !quit {\n    // Poll for (input) events\n    while SDL_PollEvent(\u0026event) \u003e 0 {\n        // if the quit event is triggered ...\n        if event.type == SDL_QUIT.rawValue {\n            // ... quit the run loop\n            quit = true\n        }\n    }\n\n    // wait 100 ms\n    SDL_Delay(100)\n}\n\n// Destroy the window\nSDL_DestroyWindow(window)\n\n// Quit all SDL systems\nSDL_Quit()\n```\n\n### Metal + macOS\n\nThere is another demo displaying a SDL2 demo window at [Sources/Demos/MetalApp](Sources/Demos/MetalApp).\n\n\n## 💁 Help needed\n\nThis project is in an early stage and needs a lot of love.\nIf you are interested in contributing, please feel free to do so!\n\nThings that need to be done are, among others:\n\n- [ ] Wrap more SDL2 functions and types\n- [ ] Write some additional tests to improve coverage\n\n## 🏷️ Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/ctreffs/SwiftSDL2/tags). \n\n## ✍️ Authors\n\n* [Christian Treffs](https://github.com/ctreffs)\n\nSee also the list of [contributors](https://github.com/ctreffs/SwiftSDL2/contributors) who participated in this project.\n\n## 🔏 Licenses\n\nThis project is licensed under the zlib License - see the [LICENSE](LICENSE) file for details.\n\n* SDL2 licensed under [zlib license](https://www.libsdl.org/license.php)\n\n\n## 🙏 Original code\n\nSince Swift SDL2 is merely a wrapper around [**SDL2**](https://www.libsdl.org) it obviously depends on it.       \nSupport them if you can!  \nSee \u003chttps://www.libsdl.org/credits.php\u003e\n\n## ☮️ Alternatives\n\n* \u003chttps://github.com/PureSwift/CSDL2\u003e\n* \u003chttps://github.com/jaz303/CSDL2.swift\u003e\n* \u003chttps://github.com/latencyzero/CSDL2\u003e\n* \u003chttps://github.com/lightive/CSDL2\u003e\n* \u003chttps://github.com/sunlubo/CSDL2\u003e\n* \u003chttps://github.com/KevinVitale/SwiftSDL\u003e\n* \u003chttps://github.com/adagio/swiftsdl2\u003e\n* \u003chttps://github.com/latencyzero/SwiftSDL\u003e\n* \u003chttps://github.com/sunlubo/SwiftSDL2\u003e\n* \u003chttps://github.com/SwiftSDL/Demo\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctreffs%2Fswiftsdl2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctreffs%2Fswiftsdl2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctreffs%2Fswiftsdl2/lists"}