Swift Package Index


A Swift wrapper for the SDL2 API


  • The latest stable release is 0.0.7. Released 2 years ago.
  • The last commit to master was almost 2 years ago.

Swift Version Compatibility

  • 0.0.7 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.0.7 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

SwiftSDL2

A Swift wrapper for the SDL2 API

Installation

You should install SDL2 before use this library, on macOS, you can:

brew install sdl2

Swift Package Manager

SwiftSDL2 primarily uses SwiftPM as its build tool, so we recommend using that as well. If you want to depend on SwiftFFmpeg in your own project, it's as simple as adding a dependencies clause to your Package.swift:

dependencies: [
    .package(url: "https://github.com/sunlubo/SwiftSDL2.git", from: "0.0.1")
]

Usage

import SwiftSDL2
import Darwin

try SDL.initialize(flags: [.video])

let window = try Window(title: "Hello", width: 640, height: 480, flags: .resizable)
let renderer = try Renderer(window: window)

while let event = Events.wait(), event.type != EventType.quit.rawValue {
  let x = arc4random() % 640
  let y = arc4random() % 480
  let rect = Rect(x: Int(x), y: Int(y), w: 100, h: 50)

  try renderer.setDrawColor(.white)
  try renderer.clear()
  try renderer.drawRect(rect)
  try renderer.setDrawColor(.random)
  try renderer.fillRect(rect)
  renderer.present()
}

SDL.quit()