summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-08-28 20:51:55 -0400
committerLLLL Colonq <llll@colonq>2026-08-28 20:52:14 -0400
commit8567564e6df6efbcf138b390ba181b8ebb118fa1 (patch)
treee43f62ef593ef5211722335dcb3c9d72e54230b4
parentfece4fc3d4decb70c94b49ab854fa9ae93b4d887 (diff)
gastro: render test scene
-rw-r--r--flake.lock6
-rw-r--r--flake.nix2
-rw-r--r--gastro/.envrc2
-rw-r--r--gastro/Makefile4
-rw-r--r--gastro/include/lcq/gastro/test.h11
-rw-r--r--gastro/src/main.c200
-rw-r--r--gastro/src/test.c203
-rw-r--r--gastro/test.qoibin0 -> 352913 bytes
-rw-r--r--pit/Makefile7
-rw-r--r--qoi/.envrc2
10 files changed, 231 insertions, 206 deletions
diff --git a/flake.lock b/flake.lock
index 286dd77..c900437 100644
--- a/flake.lock
+++ b/flake.lock
@@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1738553537,
- "narHash": "sha256-HrrsuYIOl14dreCDUsXQGrWxdiU8LPKxcIo759jUk6Q=",
+ "lastModified": 1787814960,
+ "narHash": "sha256-PYZq1qzCJXC2zGI0mH07vrZBsw6DRBAOX0jN1pPtqOQ=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "2d31b9476b7c6f5b029e595586b0b112a7ad130b",
+ "rev": "c27cdad491a991b11ed731760aa2ef8db0cb0410",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index 9421eed..601b232 100644
--- a/flake.nix
+++ b/flake.nix
@@ -13,7 +13,7 @@
lcq = builtins.mapAttrs (nm: _: (import ./${nm}/packages.nix) pkgs lcq) subpackages;
defaultShell = {
nativeBuildInputs = [
- pkgs.musl
+ # pkgs.musl
pkgs.valgrind
pkgs.universal-ctags
];
diff --git a/gastro/.envrc b/gastro/.envrc
index c4b17d7..321526b 100644
--- a/gastro/.envrc
+++ b/gastro/.envrc
@@ -1 +1 @@
-use_flake
+use_flake .#gastro
diff --git a/gastro/Makefile b/gastro/Makefile
index 9a99afd..3a99e10 100644
--- a/gastro/Makefile
+++ b/gastro/Makefile
@@ -1,12 +1,12 @@
CC ?= gcc
AR ?= ar
override CPPFLAGS += -MMD -MP
-override CFLAGS += -O2 --std=c99 -g -Ideps/ -Isrc/ -Iinclude/ -Wall -Wextra -Wconversion -Wformat-security -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wnull-dereference -Wfloat-equal -Wundef -Wpointer-arith -Wbad-function-cast -Wlogical-op -Wmissing-braces -Wcast-align -Wstrict-overflow=5
+override CFLAGS += --std=c99 -g -Ideps/ -Isrc/ -Iinclude/ -Wall -Wextra -Wconversion -Wformat-security -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wnull-dereference -Wfloat-equal -Wundef -Wpointer-arith -Wbad-function-cast -Wlogical-op -Wmissing-braces -Wcast-align -Wstrict-overflow=5 -fwrapv
override LDFLAGS += -g -lraylib -lcolonq-qoi
BUILD = build_$(CC)
-SRCS := src/gastro.c src/trig.c
+SRCS := src/gastro.c src/trig.c src/test.c
CHK_SOURCES ?= $(SRCS)
OBJECTS := $(SRCS:src/%.c=$(BUILD)/%.o)
EXE := gastro
diff --git a/gastro/include/lcq/gastro/test.h b/gastro/include/lcq/gastro/test.h
new file mode 100644
index 0000000..cf4e1d2
--- /dev/null
+++ b/gastro/include/lcq/gastro/test.h
@@ -0,0 +1,11 @@
+#ifndef LCOLONQ_GASTRO_TEST_H
+#define LCOLONQ_GASTRO_TEST_H
+
+#include <lcq/prelude.h>
+#include <lcq/gastro.h>
+#include <lcq/qoi.h>
+
+bool gastro_test_create(void);
+void gastro_test_render(gastro_ctx *ctx);
+
+#endif
diff --git a/gastro/src/main.c b/gastro/src/main.c
index af2e3aa..b0caf7c 100644
--- a/gastro/src/main.c
+++ b/gastro/src/main.c
@@ -6,204 +6,18 @@
#include <lcq/qoi.h>
#include <lcq/gastro.h>
+#include <lcq/gastro/test.h>
/* #include "../converted_model.h" */
-i64 off = 0;
-qoi_color *TEXTURE;
-i64 TEXTURE_WIDTH;
-i64 TEXTURE_HEIGHT;
-
-#define QUADIDX(p0, p1, p2, p3) p0, p1, p2, p2, p3, p0
-#define COLOR(r, g, b) gastro_fix_new(r), gastro_fix_new(g), gastro_fix_new(b)
-static void draw_quad(gastro_ctx *ctx, gastro_program *p) {
- gastro_fix sz = GASTRO_FIX_HALF;
- gastro_fix verts[] = {
- /* front */
- -sz, -sz, -sz, 0, 0,
- +sz, -sz, -sz, GASTRO_FIX_ONE, 0,
- +sz, +sz, -sz, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- -sz, +sz, -sz, 0, GASTRO_FIX_ONE
- };
- i64 idxs[] = {
- QUADIDX(0, 1, 2, 3), /* front */
- };
- gastro_render_triangles(ctx, p, verts, 5, idxs, 2);
-}
-static void draw_cube(gastro_ctx *ctx, gastro_program *p) {
- static gastro_fix verts[] = {
- /* front */
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
- /* right */
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
- /* left */
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, 0,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
- /* top */
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
- /* bottom */
- -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
- +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
- /* back */
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, 0,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE
- };
- static i64 idxs[] = {
- QUADIDX(0, 1, 2, 3), /* front */
- QUADIDX(4, 5, 6, 7), /* right */
- QUADIDX(8, 9, 10, 11), /* left */
- QUADIDX(12, 13, 14, 15), /* top */
- QUADIDX(16, 17, 18, 19), /* bottom */
- QUADIDX(20, 21, 22, 23) /* back */
- };
- gastro_render_triangles(ctx, p, verts, 5, idxs, 12);
-}
-static void draw_pyramid(gastro_ctx *ctx, gastro_program *p) {
- static gastro_fix verts[] = {
- /* front */
- 0, +GASTRO_FIX_HALF, 0, 0, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- /* right */
- 0, +GASTRO_FIX_HALF, 0, 0, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- /* left */
- 0, +GASTRO_FIX_HALF, 0, 0, 0,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- /* back */
- 0, +GASTRO_FIX_HALF, 0, 0, 0,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- /* bottom */
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
- +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
- -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
- };
- static i64 idxs[] = {
- 0, 1, 2,
- 3, 4, 5,
- 6, 7, 8,
- 9, 10, 11,
- QUADIDX(12, 13, 14, 15),
- };
- gastro_render_triangles(ctx, p, verts, 5, idxs, 6);
-}
-
-static gastro_vec4 vertex_shader(gastro_ctx *ctx, gastro_vec3 in, gastro_fix *attrs, i64 attrs_len) {
- gastro_fix x = gastro_fix_from_double((double) off / 1000.0);
- gastro_vec4 v = gastro_vec4_new(in.x, in.y, in.z, GASTRO_FIX_ONE);
- gastro_mat4x4 scale = gastro_mat4x4_new(
- gastro_fix_from_double(1.0), 0, 0, 0,
- 0, gastro_fix_from_double(1.0), 0, 0,
- 0, 0, gastro_fix_from_double(1.0), 0,
- 0, 0, 0, GASTRO_FIX_ONE
- );
- u8 theta = (u8) (off / 4);
- /* u8 theta = 13; */
- gastro_mat4x4 rot = gastro_mat4x4_new(
- GASTRO_FIX_ONE, 0, 0, 0,
- 0, gastro_cos(theta), -gastro_sin(theta), 0,
- 0, gastro_sin(theta), gastro_cos(theta), 0,
- 0, 0, 0, GASTRO_FIX_ONE
- );
- gastro_mat4x4 trans = gastro_mat4x4_new(
- GASTRO_FIX_ONE, 0, 0, gastro_fix_new(0), /* x,*/
- 0, GASTRO_FIX_ONE, 0, gastro_fix_new(1),
- 0, 0, GASTRO_FIX_ONE, gastro_fix_new(-3),
- 0, 0, 0, GASTRO_FIX_ONE
- );
- gastro_mat4x4 proj = gastro_mat4x4_new(
- GASTRO_FIX_ONE, 0, 0, 0,
- 0, GASTRO_FIX_ONE, 0, 0,
- 0, 0, GASTRO_FIX_ONE, 0,
- 0, 0, GASTRO_FIX_ONE, 0
- );
- v = gastro_mat4x4_mul_vec4(scale, v);
- v = gastro_mat4x4_mul_vec4(rot, v);
- v = gastro_mat4x4_mul_vec4(trans, v);
- v = gastro_mat4x4_mul_vec4(proj, v);
- return v;
-}
-
-static gastro_color fragment_shader_texture(gastro_ctx *ctx, gastro_vec3 in, gastro_fix *attrs, i64 attrs_len) {
- gastro_fix u = attrs[0];
- gastro_fix v = attrs[1];
- i64 x = gastro_fix_to_i64(gastro_fix_mul(gastro_fix_new(TEXTURE_WIDTH), u));
- i64 y = gastro_fix_to_i64(gastro_fix_mul(gastro_fix_new(TEXTURE_HEIGHT), v));
- qoi_color c = TEXTURE[y * TEXTURE_WIDTH + x];
- return gastro_color_new(c.r, c.g, c.b, c.a);
-}
-
-static gastro_color fragment_shader_teapot(gastro_ctx *ctx, gastro_vec3 in, gastro_fix *attrs, i64 attrs_len) {
- u8 col = (u8) gastro_fix_to_i64(
- gastro_fix_mul(
- gastro_fix_new(0xff),
- gastro_fix_div(in.z, gastro_fix_new(8))
- )
- );
- return gastro_color_new(0xff - col, 0xff - col, 0xff - col, 0xff);
-}
-
-void load_image(char *path) {
- FILE *f;
- u8 *buf;
- i64 len;
- qoi_decoder q;
- qoi_header h;
- qoi_color *pixels;
- if (!(f = fopen(path, "r"))) {
- fprintf(stderr, "failed to open file: %s\n", path);
- return;
- }
- fseek(f, 0, SEEK_END);
- len = ftell(f);
- fseek(f, 0, SEEK_SET);
- buf = calloc((size_t) len, sizeof(u8));
- fread(buf, sizeof(u8), (size_t) len, f);
- qoi_decoder_new(&q, buf, len);
- if (!qoi_decode_header(&q, &h)) {
- fprintf(stderr, "failed to decode header\n");
- return;
- }
- pixels = calloc(h.width * h.height, sizeof(qoi_color));
- qoi_decode(&q, &h, pixels);
- TEXTURE = pixels;
- TEXTURE_WIDTH = h.width;
- TEXTURE_HEIGHT = h.height;
-}
-
int main(int argc, char **argv) {
gastro_ctx ctx;
u32 width = 256, height = 256;
gastro_color *pixels = calloc(width * height, sizeof(gastro_color));
gastro_fix *depth = calloc(width * height, sizeof(gastro_fix));
- gastro_program p;
gastro_ctx_init(&ctx, width, height, pixels, depth);
- p.vertex = vertex_shader;
- p.fragment = fragment_shader_texture;
-
- load_image("mark2.qoi");
- /* gastro_draw_clear(&ctx, gastro_color_new(0, 0, 0, 0xff)); */
- /* draw_model(&ctx, &p); */
+ gastro_test_create();
InitWindow(800, 600, "test");
{
@@ -217,17 +31,9 @@ int main(int argc, char **argv) {
tex = LoadTextureFromImage(im);
SetTargetFPS(300);
while (!WindowShouldClose()) {
- i64 i;
Vector2 pos;
pos.x = 10; pos.y = 10;
- gastro_draw_clear(&ctx, gastro_color_new(0, 0, 0, 0xff));
- for (i = 0; i < 1; ++i) {
- draw_pyramid(&ctx, &p);
- }
- /* draw_quad(&ctx, &p); */
- /* draw_model(&ctx, &p); */
- off += 1;
- off %= 256 * 64;
+ gastro_test_render(&ctx);
BeginDrawing();
ClearBackground(RED);
UpdateTexture(tex, ctx.pixels);
diff --git a/gastro/src/test.c b/gastro/src/test.c
new file mode 100644
index 0000000..46ce6b1
--- /dev/null
+++ b/gastro/src/test.c
@@ -0,0 +1,203 @@
+#include <lcq/gastro/test.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+static i64 off = 0;
+static gastro_program program;
+static qoi_color *texture;
+static i64 texture_width;
+static i64 texture_height;
+
+#define QUADIDX(p0, p1, p2, p3) p0, p1, p2, p2, p3, p0
+#define COLOR(r, g, b) gastro_fix_new(r), gastro_fix_new(g), gastro_fix_new(b)
+static void draw_quad(gastro_ctx *ctx, gastro_program *p) {
+ gastro_fix sz = GASTRO_FIX_HALF;
+ gastro_fix verts[] = {
+ /* front */
+ -sz, -sz, -sz, 0, 0,
+ +sz, -sz, -sz, GASTRO_FIX_ONE, 0,
+ +sz, +sz, -sz, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ -sz, +sz, -sz, 0, GASTRO_FIX_ONE
+ };
+ i64 idxs[] = {
+ QUADIDX(0, 1, 2, 3), /* front */
+ };
+ gastro_render_triangles(ctx, p, verts, 5, idxs, 2);
+}
+static void draw_cube(gastro_ctx *ctx, gastro_program *p) {
+ static gastro_fix verts[] = {
+ /* front */
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
+ /* right */
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
+ /* left */
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, 0,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
+ /* top */
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
+ /* bottom */
+ -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
+ +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
+ /* back */
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, 0,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE
+ };
+ static i64 idxs[] = {
+ QUADIDX(0, 1, 2, 3), /* front */
+ QUADIDX(4, 5, 6, 7), /* right */
+ QUADIDX(8, 9, 10, 11), /* left */
+ QUADIDX(12, 13, 14, 15), /* top */
+ QUADIDX(16, 17, 18, 19), /* bottom */
+ QUADIDX(20, 21, 22, 23) /* back */
+ };
+ gastro_render_triangles(ctx, p, verts, 5, idxs, 12);
+}
+static void draw_pyramid(gastro_ctx *ctx, gastro_program *p) {
+ static gastro_fix verts[] = {
+ /* front */
+ 0, +GASTRO_FIX_HALF, 0, 0, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ /* right */
+ 0, +GASTRO_FIX_HALF, 0, 0, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ /* left */
+ 0, +GASTRO_FIX_HALF, 0, 0, 0,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ /* back */
+ 0, +GASTRO_FIX_HALF, 0, 0, 0,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ /* bottom */
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, 0, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, GASTRO_FIX_ONE, 0,
+ +GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, GASTRO_FIX_ONE, GASTRO_FIX_ONE,
+ -GASTRO_FIX_HALF, -GASTRO_FIX_HALF, +GASTRO_FIX_HALF, 0, GASTRO_FIX_ONE,
+ };
+ static i64 idxs[] = {
+ 0, 1, 2,
+ 3, 4, 5,
+ 6, 7, 8,
+ 9, 10, 11,
+ QUADIDX(12, 13, 14, 15),
+ };
+ gastro_render_triangles(ctx, p, verts, 5, idxs, 6);
+}
+
+static gastro_vec4 vertex_shader(gastro_ctx *ctx, gastro_vec3 in, gastro_fix *attrs, i64 attrs_len) {
+ gastro_fix x = gastro_fix_from_double((double) off / 1000.0);
+ gastro_vec4 v = gastro_vec4_new(in.x, in.y, in.z, GASTRO_FIX_ONE);
+ gastro_mat4x4 scale = gastro_mat4x4_new(
+ gastro_fix_from_double(1.0), 0, 0, 0,
+ 0, gastro_fix_from_double(1.0), 0, 0,
+ 0, 0, gastro_fix_from_double(1.0), 0,
+ 0, 0, 0, GASTRO_FIX_ONE
+ );
+ u8 theta = (u8) (off / 4);
+ /* u8 theta = 13; */
+ gastro_mat4x4 rot = gastro_mat4x4_new(
+ GASTRO_FIX_ONE, 0, 0, 0,
+ 0, gastro_cos(theta), -gastro_sin(theta), 0,
+ 0, gastro_sin(theta), gastro_cos(theta), 0,
+ 0, 0, 0, GASTRO_FIX_ONE
+ );
+ gastro_mat4x4 trans = gastro_mat4x4_new(
+ GASTRO_FIX_ONE, 0, 0, gastro_fix_new(0), /* x,*/
+ 0, GASTRO_FIX_ONE, 0, gastro_fix_new(1),
+ 0, 0, GASTRO_FIX_ONE, gastro_fix_new(-3),
+ 0, 0, 0, GASTRO_FIX_ONE
+ );
+ gastro_mat4x4 proj = gastro_mat4x4_new(
+ GASTRO_FIX_ONE, 0, 0, 0,
+ 0, GASTRO_FIX_ONE, 0, 0,
+ 0, 0, GASTRO_FIX_ONE, 0,
+ 0, 0, GASTRO_FIX_ONE, 0
+ );
+ v = gastro_mat4x4_mul_vec4(scale, v);
+ v = gastro_mat4x4_mul_vec4(rot, v);
+ v = gastro_mat4x4_mul_vec4(trans, v);
+ v = gastro_mat4x4_mul_vec4(proj, v);
+ return v;
+}
+
+static gastro_color fragment_shader_texture(gastro_ctx *ctx, gastro_vec3 in, gastro_fix *attrs, i64 attrs_len) {
+ gastro_fix u = attrs[0];
+ gastro_fix v = attrs[1];
+ i64 x = gastro_fix_to_i64(gastro_fix_mul(gastro_fix_new(texture_width), u));
+ i64 y = gastro_fix_to_i64(gastro_fix_mul(gastro_fix_new(texture_height), v));
+ qoi_color c = texture[y * texture_width + x];
+ return gastro_color_new(c.r, c.g, c.b, c.a);
+}
+
+static gastro_color fragment_shader_teapot(gastro_ctx *ctx, gastro_vec3 in, gastro_fix *attrs, i64 attrs_len) {
+ u8 col = (u8) gastro_fix_to_i64(
+ gastro_fix_mul(
+ gastro_fix_new(0xff),
+ gastro_fix_div(in.z, gastro_fix_new(8))
+ )
+ );
+ return gastro_color_new(0xff - col, 0xff - col, 0xff - col, 0xff);
+}
+
+static void load_image(char *path) {
+ FILE *f;
+ u8 *buf;
+ i64 len;
+ qoi_decoder q;
+ qoi_header h;
+ qoi_color *pixels;
+ if (!(f = fopen(path, "r"))) {
+ fprintf(stderr, "failed to open file: %s\n", path);
+ return;
+ }
+ fseek(f, 0, SEEK_END);
+ len = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ buf = calloc((size_t) len, sizeof(u8));
+ fread(buf, sizeof(u8), (size_t) len, f);
+ qoi_decoder_new(&q, buf, len);
+ if (!qoi_decode_header(&q, &h)) {
+ fprintf(stderr, "failed to decode header\n");
+ return;
+ }
+ pixels = calloc(h.width * h.height, sizeof(qoi_color));
+ qoi_decode(&q, &h, pixels);
+ texture = pixels;
+ texture_width = h.width;
+ texture_height = h.height;
+}
+
+bool gastro_test_create() {
+ program.vertex = vertex_shader;
+ program.fragment = fragment_shader_texture;
+ load_image("test.qoi");
+}
+
+void gastro_test_render(gastro_ctx *ctx) {
+ gastro_draw_clear(ctx, gastro_color_new(0, 0, 0, 0xff));
+ for (i64 i = 0; i < 1; ++i) {
+ draw_pyramid(ctx, &program);
+ }
+ /* draw_quad(&ctx, &p); */
+ /* draw_model(&ctx, &p); */
+ off += 1;
+ off %= 256 * 64;
+}
diff --git a/gastro/test.qoi b/gastro/test.qoi
new file mode 100644
index 0000000..6cc4cf8
--- /dev/null
+++ b/gastro/test.qoi
Binary files differ
diff --git a/pit/Makefile b/pit/Makefile
index 2f74aba..0a9da88 100644
--- a/pit/Makefile
+++ b/pit/Makefile
@@ -29,7 +29,9 @@ bindir ?= $(exec_prefix)/bin
includedir ?= $(prefix)/include
libdir ?= $(exec_prefix)/lib
-.PHONY: all clean install install-bin install-headers install-core install-native check-syntax
+GDBFLAGS ?=
+
+.PHONY: all clean install install-bin install-headers install-core install-native check-syntax gdb
all: $(EXE) $(LIB_CORE) $(LIB_NATIVE)
@@ -80,6 +82,9 @@ install-native: $(LIB_NATIVE)
check-syntax: TAGS
gcc $(CFLAGS) -fsyntax-only $(CHK_SOURCES)
+gdb: $(EXE)
+ gdb $(GDBFLAGS) $(EXE)
+
-include $(BUILD)/main.d
-include $(OBJECTS_CORE:.o=.d)
-include $(OBJECTS_NATIVE:.o=.d)
diff --git a/qoi/.envrc b/qoi/.envrc
index c4b17d7..a552670 100644
--- a/qoi/.envrc
+++ b/qoi/.envrc
@@ -1 +1 @@
-use_flake
+use_flake .#qoi