aboutsummaryrefslogtreecommitdiff
path: root/sdl2
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2021-12-09 14:36:32 +0100
committerDrew DeVault <sir@cmpwn.com>2021-12-09 14:36:32 +0100
commit07046a3b2c2d0b6a5dfaaab70e5ea71e8334df1b (patch)
treee134285c86f6052b9c19ae7755acafa0137e215b /sdl2
parentAdd README.md (diff)
downloadhare-chip8-07046a3b2c2d0b6a5dfaaab70e5ea71e8334df1b.tar.gz
sdl2::image: initial commit
Some additional things which were needed to make this work were also added.
Diffstat (limited to '')
-rw-r--r--sdl2/image/image.ha28
-rw-r--r--sdl2/pixels.ha38
-rw-r--r--sdl2/rect.ha29
-rw-r--r--sdl2/render.ha16
-rw-r--r--sdl2/surface.ha25
5 files changed, 136 insertions, 0 deletions
diff --git a/sdl2/image/image.ha b/sdl2/image/image.ha
new file mode 100644
index 0000000..03301e9
--- /dev/null
+++ b/sdl2/image/image.ha
@@ -0,0 +1,28 @@
+// TODO: Flesh me out
+// TODO: SDL_RWops
+use sdl2;
+
+// Flags for [[init]].
+export type init_flags = enum int {
+ NONE = 0,
+ JPG = 0x00000001,
+ PNG = 0x00000002,
+ TIF = 0x00000004,
+ WEBP = 0x00000008,
+};
+
+// Loads dynamic libraries and prepares them for use. Flags should be one or
+// more flags from IMG_InitFlags OR'd together.
+//
+// Returns the flags successfully initialized, or 0 on failure.
+export @symbol("IMG_Init") fn init(flags: init_flags) int;
+
+// Unloads libraries loaded with [[init]]
+export @symbol("IMG_Quit") fn quit() void;
+
+// Load an image from a file path.
+export @symbol("IMG_Load") fn load(file: const *char) nullable *sdl2::surface;
+
+// Load an image directly into a render texture.
+export @symbol("IMG_LoadTexture") fn load_texture(renderer: *sdl2::renderer,
+ file: const *char) nullable *sdl2::texture;
diff --git a/sdl2/pixels.ha b/sdl2/pixels.ha
new file mode 100644
index 0000000..8227067
--- /dev/null
+++ b/sdl2/pixels.ha
@@ -0,0 +1,38 @@
+// TODO: Flesh me out
+
+export type color = struct {
+ r: u8,
+ g: u8,
+ b: u8,
+ a: u8,
+};
+
+export type palette = struct {
+ ncolors: int,
+ colors: *color,
+ version: u32,
+ refcount: int,
+};
+
+// Note: Everything in the pixel format structure is read-only.
+export type pixelformat = struct {
+ format: u32, // TODO
+ palette: *palette,
+ bitsperpixel: u8,
+ bytesperpixel: u8,
+ padding: [2]u8,
+ rmask: u32,
+ gmask: u32,
+ bmask: u32,
+ amask: u32,
+ rloss: u8,
+ gloss: u8,
+ bloss: u8,
+ aloss: u8,
+ rshift: u8,
+ gshift: u8,
+ bshift: u8,
+ ashift: u8,
+ refcount: int,
+ next: nullable *pixelformat,
+};
diff --git a/sdl2/rect.ha b/sdl2/rect.ha
new file mode 100644
index 0000000..00fae87
--- /dev/null
+++ b/sdl2/rect.ha
@@ -0,0 +1,29 @@
+// TODO: Flesh me out
+
+// The structure that defines a point (integer)
+export type point = struct {
+ x: int,
+ y: int,
+};
+
+// The structure that defines a point (floating point)
+export type fpoint = struct {
+ x: f32,
+ y: f32,
+};
+
+// A rectangle, with the origin at the upper left (integer).
+export type rect = struct {
+ x: int,
+ y: int,
+ w: int,
+ h: int,
+};
+
+// A rectangle, with the origin at the upper left (floating point).
+export type frect = struct {
+ x: f32,
+ y: f32,
+ w: f32,
+ h: f32,
+};
diff --git a/sdl2/render.ha b/sdl2/render.ha
index e1d2c8e..d4f0671 100644
--- a/sdl2/render.ha
+++ b/sdl2/render.ha
@@ -68,3 +68,19 @@ export @symbol("SDL_RenderClear") fn render_clear(renderer: *renderer) int;
// Update the screen with rendering performed.
export @symbol("SDL_RenderPresent") fn render_present(renderer: *renderer) void;
+
+// Destroy the specified texture.
+export @symbol("SDL_DestroyTexture") fn destroy_texture(texture: *texture) void;
+
+// Query the attributes of a texture
+//
+// Returns 0 on success, or -1 if the texture is not valid.
+export @symbol("SDL_QueryTexture") fn query_texture(texture: *texture,
+ format: nullable *u32, access: nullable *int,
+ w: nullable *int, h: nullable *int) int;
+
+// Copy a portion of the texture to the current rendering target.
+//
+// Returns 0 on success, or -1 on error
+export @symbol("SDL_RenderCopy") fn render_copy(renderer: *renderer,
+ texture: *texture, srcrect: nullable *rect, dstrect: nullable *rect) int;
diff --git a/sdl2/surface.ha b/sdl2/surface.ha
new file mode 100644
index 0000000..7bbe850
--- /dev/null
+++ b/sdl2/surface.ha
@@ -0,0 +1,25 @@
+// A collection of pixels used in software blitting.
+//
+// This structure should be treated as read-only, except for 'pixels', which, if
+// not null, contains the raw pixel data for the surface.
+export type surface = struct {
+ flags: u32,
+ format: *pixelformat,
+ w: int,
+ h: int,
+ pitch: int,
+ pixels: nullable *void,
+
+ userdata: *void,
+
+ locked: int,
+ lock_data: *void,
+
+ clip_rect: rect,
+
+ map: *blitmap,
+
+ refcount: int,
+};
+
+export type blitmap = void;