import CSDL3 import Foundation public class Renderer { var handle: OpaquePointer var scale: (x: Float, y: Float) { get { var x: Float = 0.0 var y: Float = 0.0 SDL_GetRenderScale(handle, &x, &y) return (x, y) } } public func setScale(newScale: (x: Float, y: Float)) throws { try SDL_SetRenderScale(handle, newScale.x, newScale.y).sdlThrow(type: type(of: self)) } public init(_ window: Window, name: String? = nil) throws { handle = try SDL_CreateRenderer(window.handle, name).sdlThrow(type: type(of: self)) } deinit { SDL_DestroyRenderer(handle) } public func clear() throws { try SDL_RenderClear(handle).sdlThrow(type: type(of: self)) } public func renderTexture( _ texture: Texture, srcRect: Rect? = nil, dstRect: Rect? = nil ) throws { var srcRectPtr: UnsafePointer? = nil var dstRectPtr: UnsafePointer? = nil if let srcRect = srcRect { srcRectPtr = withUnsafePointer(to: srcRect.handle) { UnsafePointer($0) } } if let dstRect = dstRect { dstRectPtr = withUnsafePointer(to: dstRect.handle) { UnsafePointer($0) } } try SDL_RenderTexture( handle, texture.handle, srcRectPtr, dstRectPtr ).sdlThrow(type: type(of: self)) } public func present() { SDL_RenderPresent(handle) } }