assets: wip rendering tiles
authorLukas Krickl <lukas@krickl.dev>
Tue, 24 Feb 2026 15:56:31 +0000 (16:56 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 24 Feb 2026 15:56:31 +0000 (16:56 +0100)
makefile
src/lrts.c
src/lrts.h
src/r_assets.c [new file with mode: 0644]
src/r_assets.h [new file with mode: 0644]
src/r_render.c
src/t_tile.h
src/u_math.c
src/u_math.h

index bf1d2c9e6e742222d997ba0230da8deeab6cae0c..9fbcdf6a1cc5b5848e28a8084600629c51a85262 100644 (file)
--- a/makefile
+++ b/makefile
@@ -11,7 +11,7 @@ OBJS:=
 
 CCOBJ=$(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS)
 
-all: bin test
+all: bin btest
 
 release: 
        make DBGCFLAGS="" DBGLDFLAGS=""
@@ -28,9 +28,18 @@ test.o: src/test.c FORCE
 bin: main.o $(OBJS) 
        $(CC) -o $(NAME) main.o $(OBJS) $(CFLAGS) $(LDFLAGS)
 
-test: test.o $(OBJS) 
+btest: test.o $(OBJS) 
        $(CC) -o $(TEST_NAME) test.o $(OBJS) $(CFLAGS) $(LDFLAGS) -fsanitize=address 
 
+
+.PHONY: test
+test: $(TEST_NAME)
+       ./$(TEST_NAME)
+
+.PHONY: run
+run: $(NAME)
+       ./$(NAME)
+
 .PHONY: clean
 clean:
        rm -f ./*.o
index 193c2e079cec2ee8ec9dc2c29dc262c112ed2b6b..2245bf0c44c844c73391aa06fcdac52e2be6d84c 100644 (file)
@@ -28,8 +28,8 @@ void lrts_version(void) {
 /**
  * The default render size
  */
-#define U_RENDER_W 640
-#define U_RENDER_H 640
+#define U_RENDER_W 896
+#define U_RENDER_H 504
 
 struct u_vec2 lrts_get_render_res(void) {
        struct lrts_config *cfg = lrts_cfg();
index 04f17aff266ab15ab02d81a6a1505d0627e87dc9..ffb0f6dc6fb08c7aeaaaece9d3e91a77ed67b364 100644 (file)
@@ -55,6 +55,7 @@
 #include "t_camera.c"
 #include "r_render.c"
 #include "r_color.c"
+#include "r_assets.c"
 
 #endif
 
diff --git a/src/r_assets.c b/src/r_assets.c
new file mode 100644 (file)
index 0000000..7b36631
--- /dev/null
@@ -0,0 +1,30 @@
+#include "r_assets.h"
+#include "r_render.h"
+
+#define R_SOLID_TILE_OUTLINE_COLOR 0xFF0000FF
+
+void r_draw_solid_isometric_tile(i32 x, i32 y, r_color color, r_color outline_color) {
+       u32 i = 0;
+       u32 j = 0;
+
+       LRTS_UNUSED(outline_color);
+       LRTS_UNUSED(x);
+       LRTS_UNUSED(y);
+
+       for (i = 0; i < R_TILE_W; i++) {
+               for (j = 1; j < R_TILE_H-1; j++) {
+                       r_draw_pixel(&r_framebuffer, x+i, y+j, color);
+               }
+       }
+}
+
+void r_draw_tile(struct t_tile *t, i32 x, i32 y) {
+       switch (t->type) {
+               case T_TILE_TYPE_NONE:
+                       break;
+               case T_TILE_TYPE_GRASS:
+                       r_draw_solid_isometric_tile(x, y, 0x44FF00FF, R_SOLID_TILE_OUTLINE_COLOR);
+                       break;
+       }
+}
+
diff --git a/src/r_assets.h b/src/r_assets.h
new file mode 100644 (file)
index 0000000..2da488f
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef R_ASSETS_H__
+#define R_ASSETS_H__
+
+#define R_TILE_W 32
+#define R_TILE_H 16
+
+/**
+ * This module contains asset descriptions
+ * for all in-game asset types
+ * It provides an interface to obtain e.g. tile gfx based on the tile type.
+ * 
+ * Gfx assets:
+ *     all gfx assets have a built-in representation that does not require loading any 
+ *     resources. They serve as a fallback in case an image cannot be loaded.
+ */
+
+#include "t_tile.h"
+#include "u_defs.h"
+
+/* 
+ * Draws a tile to the frame buffer at x, y.
+ * Attempts to load the tile from the tile sheet
+ * if no tile sheet is availabel a fallback is drawn instead
+ */
+void r_draw_tile(struct t_tile *t, i32 x, i32 y);
+
+
+#endif
index d53c8b72ada126dacb17bbb43ceb598cea2bc170..c0d5b755e9708c588f98b33d9cf3363d441b4b3d 100644 (file)
@@ -1,7 +1,8 @@
 #include "r_render.h"
 #include "r_color.h"
 #include "p_draw.h"
-
+#include "t_tile.h"
+#include "r_assets.h"
 
 struct r_framebuffer r_framebuffer;
 
@@ -21,12 +22,13 @@ void r_draw_pixel(struct r_framebuffer *fb, i32 x, i32 y, r_color color) {
 }
 
 void r_render_frame() {
-       p_draw_begin();
+       struct t_tile t;
 
-       r_draw_pixel(&r_framebuffer, 0, 0, 0xFF0000FF);
-       r_draw_pixel(&r_framebuffer, 1, 1, 0xFF0000FF);
-       r_draw_pixel(&r_framebuffer, 2, 2, 0xFF0000FF);
-       r_draw_pixel(&r_framebuffer, r_framebuffer.width-1, r_framebuffer.height-1, 0xFF0000FF);
+       p_draw_begin();
+       
+       /* draw test tile */
+       t.type = T_TILE_TYPE_GRASS;
+       r_draw_tile(&t, 128, 128);
 
        p_draw_end();
        p_draw_present();
index d5424a6c2cf33a5eac23a4264bfa4832cae20db4..a67e36310bac8e97bf97d9b084903c8757c906d4 100644 (file)
@@ -4,7 +4,8 @@
 #include "u_defs.h"
 
 enum t_tile_types {
-       T_TILE_TYPE_NONE = 0
+       T_TILE_TYPE_NONE = 0,
+       T_TILE_TYPE_GRASS
 };
 
 enum t_tile_flags {
index ff65375bd516c3e720b7a24c34ba8c1e0b022662..a9ceaa259278996094303b7bc0e56c3a3ad56ac4 100644 (file)
@@ -44,3 +44,12 @@ struct u_fp u_fp_mod(struct u_fp a, struct u_fp b) {
        lrts_todo("");
        return c;
 }
+
+struct u_vec2 u_vec2_mul(i32 n, struct u_vec2 v) {
+       struct u_vec2 r;
+
+       r.x = v.x * n;
+       r.y = v.y * n;
+               
+       return r;
+}
index 543c97b1bea95f0fc54b968d6e13d5ad42dfd750..2aa23745178ba7b40a1e0fc0037b8414fdf1fd85 100644 (file)
@@ -19,8 +19,8 @@ struct u_fp {
  * A simple 2d vector
  */
 struct u_vec2 {
-       u32 x;
-       u32 y;
+       i32 x;
+       i32 y;
 };
 
 /*
@@ -37,6 +37,11 @@ struct u_fp u_fp_mul(struct u_fp a, struct u_fp b);
 struct u_fp u_fp_div(struct u_fp a, struct u_fp b);
 struct u_fp u_fp_mod(struct u_fp a, struct u_fp b);
 
+/*
+ * Multiplies an integer with a vec2 reutnrs the resulting vector
+ */
+struct u_vec2 u_vec2_mul(i32 n, struct u_vec2 v);
+
 /* Clamps an integer value between min and max */
 #define U_CLAMP(v, min, max) if (v < min) { v = min; } if (v > max) { v = max; }