33 lines
1016 B
Swift
33 lines
1016 B
Swift
import Foundation
|
|
import CSDL2
|
|
import CSDL2_Image
|
|
|
|
public class Texture {
|
|
public var handle: OpaquePointer
|
|
|
|
public init(_ renderer: Renderer, width: Int, height: Int) throws {
|
|
handle = try SDL_CreateTexture(
|
|
renderer.handle,
|
|
SDL_PIXELFORMAT_RGB24.rawValue,
|
|
Int32(SDL_TEXTUREACCESS_TARGET.rawValue),
|
|
Int32(width), Int32(height)
|
|
).sdlThrow(type: type(of: self))
|
|
}
|
|
|
|
public init(from imagePath: String, renderer: Renderer) throws {
|
|
handle = try IMG_LoadTexture(renderer.handle, imagePath).sdlThrow(type: type(of: self))
|
|
}
|
|
|
|
public init(from surface: Surface, renderer: Renderer) throws {
|
|
handle = try SDL_CreateTextureFromSurface(renderer.handle, surface.handle).sdlThrow(type: type(of: self))
|
|
}
|
|
|
|
deinit {
|
|
SDL_DestroyTexture(handle)
|
|
}
|
|
|
|
public func setColorMod(color: Color) throws {
|
|
try SDL_SetTextureColorMod(handle, color.r, color.g, color.b).sdlThrow(type: type(of: self))
|
|
}
|
|
}
|