aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy.h
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-08 19:30:44 -0400
committeriamcheeseman <[email protected]>2026-05-08 19:30:44 -0400
commit5625a8626fe303748b205c80f87035593cf2f561 (patch)
tree5e5a5adb6f1265358ae21ec47cd384362345df5a /teensy/teensy.h
Initial commit
Diffstat (limited to 'teensy/teensy.h')
-rw-r--r--teensy/teensy.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/teensy/teensy.h b/teensy/teensy.h
new file mode 100644
index 0000000..c8b8e9d
--- /dev/null
+++ b/teensy/teensy.h
@@ -0,0 +1,108 @@
+#ifndef TEENSY_H_
+#define TEENSY_H_
+
+#include "common.h"
+#include "context.h"
+
+#define ty_vec2(x, y) ((struct ty_vec2){x, y})
+#define ty_vec2i(x, y) ((struct ty_vec2i){x, y})
+#define ty_color(R, G, B) ((struct ty_color){R, G, B})
+
+#define TY_COLOR_BLACK ty_color(0, 0, 0 )
+#define TY_COLOR_RED ty_color(255, 0, 0 )
+#define TY_COLOR_GREEN ty_color(0, 255, 0 )
+#define TY_COLOR_YELLOW ty_color(255, 255, 0 )
+#define TY_COLOR_BLUE ty_color(0, 0, 255)
+#define TY_COLOR_MAGENTA ty_color(255, 0, 255)
+#define TY_COLOR_CYAN ty_color(0, 255, 255)
+#define TY_COLOR_WHITE ty_color(255, 255, 255)
+
+struct ty_creation_hints {
+ int win_width;
+ int win_height;
+ const char *win_title;
+ int ticrate;
+};
+
+struct ty_ctx {
+ struct ty_creation_hints creation_hints;
+ double ticrate;
+ double prev_tic_ts;
+};
+
+struct ty_color {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+};
+
+struct ty_vec2 {
+ float x;
+ float y;
+};
+
+struct ty_vec2i {
+ int x;
+ int y;
+};
+
+struct ty_rect {
+ float x;
+ float y;
+ float w;
+ float h;
+};
+
+struct ty_recti {
+ int x;
+ int y;
+ int w;
+ int h;
+};
+
+struct ty_image {
+ struct ty_color *data;
+ int width;
+ int height;
+};
+
+struct ty_renderer {
+ struct ty_image screen;
+};
+
+void ty_init(struct ty_creation_hints creation_hints);
+void ty_deinit(void);
+
+// Whether or not the main loop should continue executing.
+bool ty_is_game_running(void);
+// Gets the real time that the game has been running.
+double ty_get_time(void);
+// Handle events, tick game logic, etc. Returns the amount of times you should
+// tic.
+int ty_tick(void);
+
+struct ty_image ty_create_image(int w, int h, const struct ty_color* data);
+void ty_free_image(struct ty_image img);
+struct ty_color ty_img_get_pixel(struct ty_image img, struct ty_vec2i pos);
+void ty_img_set_pixel(
+ struct ty_image img,
+ struct ty_vec2i pos,
+ struct ty_color color
+);
+
+void ty_draw_clear(struct ty_color col);
+void ty_draw_image(struct ty_image img, struct ty_vec2i pos);
+void ty_draw_image_ex(
+ struct ty_image img,
+ struct ty_recti src,
+ struct ty_recti dst
+);
+void ty_draw_rect(struct ty_recti rect, struct ty_color color);
+void ty_draw_line(
+ struct ty_vec2i start,
+ struct ty_vec2i end,
+ struct ty_color color
+);
+void ty_draw_end(void);
+
+#endif // TEENSY_H_