blob: 8a480092f141c462f8da41e50278badcfadf6c41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// TODO: Flesh me out
// TODO: SDL_RWops
use sdl2;
use strings;
// Flags for [[init]].
export type init_flags = enum int {
NONE = 0,
JPG = 0x00000001,
PNG = 0x00000002,
TIF = 0x00000004,
WEBP = 0x00000008,
};
@symbol("IMG_Init") fn _init(flags: init_flags) int;
// Loads dynamic libraries and prepares them for use. Flags should be one or
// more flags from [[init_flags]] OR'd together.
export fn init(flags: init_flags) (void | sdl2::error) = {
return sdl2::wrapvoid(_init(flags));
};
// Unloads libraries loaded with [[init]]
export @symbol("IMG_Quit") fn quit() void;
@symbol("IMG_Load") fn _load(file: const *char) nullable *sdl2::surface;
// Load an image from a file path.
export fn load(file: str) (*sdl2::surface | sdl2::error) = {
const file = strings::to_c(file);
defer free(file);
return sdl2::wrapptr(_load(file))?: *sdl2::surface;
};
@symbol("IMG_LoadTexture") fn _load_texture(renderer: *sdl2::renderer,
file: const *char) nullable *sdl2::texture;
// Load an image directly into a render texture.
export fn load_texture(
renderer: *sdl2::renderer,
file: str,
) (*sdl2::texture | sdl2::error) = {
const file = strings::to_c(file);
defer free(file);
return sdl2::wrapptr(_load_texture(renderer, file))?: *sdl2::texture;
};
|