diff options
author | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:11:21 +0200 |
---|---|---|
committer | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:51:35 +0200 |
commit | ae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch) | |
tree | 5f462459ae4b47d22114eed717d1382d08cf4dfe /sdl2/image/image.ha |
Diffstat (limited to 'sdl2/image/image.ha')
-rw-r--r-- | sdl2/image/image.ha | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sdl2/image/image.ha b/sdl2/image/image.ha new file mode 100644 index 0000000..32f8f3d --- /dev/null +++ b/sdl2/image/image.ha @@ -0,0 +1,46 @@ +// TODO: Flesh me out +// TODO: SDL_RWops +use sdl2; +use types::c; + +// Flags for [[IMG_Init]]. +export type IMG_InitFlags = enum int { + NONE = 0, + JPG = 0x00000001, + PNG = 0x00000002, + TIF = 0x00000004, + WEBP = 0x00000008, +}; + +@symbol("IMG_Init") fn _IMG_Init(flags: IMG_InitFlags) int; + +// Loads dynamic libraries and prepares them for use. Flags should be one or +// more flags from [[IMG_InitFlags]] OR'd together. +export fn IMG_Init(flags: IMG_InitFlags) (void | sdl2::error) = { + return sdl2::wrapvoid(_IMG_Init(flags)); +}; + +// Unloads libraries loaded with [[IMG_Init]] +export @symbol("IMG_Quit") fn IMG_Quit() void; + +@symbol("IMG_Load") fn _IMG_Load(file: const *c::char) nullable *sdl2::SDL_Surface; + +// Load an image from a file path. +export fn IMG_Load(file: str) (*sdl2::SDL_Surface | sdl2::error) = { + const file = c::fromstr(file); + defer free(file); + return sdl2::wrapptr(_IMG_Load(file))?: *sdl2::SDL_Surface; +}; + +@symbol("IMG_LoadTexture") fn _IMG_LoadTexture(SDL_Renderer: *sdl2::SDL_Renderer, + file: const *c::char) nullable *sdl2::SDL_Texture; + +// Load an image directly into a render texture. +export fn IMG_LoadTexture( + SDL_Renderer: *sdl2::SDL_Renderer, + file: str, +) (*sdl2::SDL_Texture | sdl2::error) = { + const file = c::fromstr(file); + defer free(file); + return sdl2::wrapptr(_IMG_LoadTexture(SDL_Renderer, file))?: *sdl2::SDL_Texture; +}; |