From 846e402b9812e2f45f13fa905e98e09b895e47f2 Mon Sep 17 00:00:00 2001 From: Matthew Stanley <1379tech@gmail.com> Date: Thu, 11 Jun 2026 15:17:22 -0700 Subject: [PATCH] gl-renderer: fix double-applied draw offset dropping terrain layers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gpu.c applies draw_offset_x/y to every primitive's coordinates before calling the gr_* facade (see gp0_exec_* — triangles, rects, sprites, lines all pre-offset), and the software raster consumes them directly (g_offset_x is never read during rasterization). The GPU triangle paths were adding s_off again, double-applying the offset. At the logos the offset is 0 so it was invisible, but in the scrolling overworld it displaced every GPU-rendered triangle by 2x the scroll, pushing the background/foreground terrain quads off-screen while sprites (drawn as rects -> software, single offset) stayed put. Net effect: "the entire overworld is gone" — only sprites survived. Drop the s_off addition in gpu_triangle/gpu_textured_triangle. Verified: the attract-demo overworld now renders full terrain (grass, mushrooms, cliffs, signpost, coins) instead of sprites on an empty gradient. Co-Authored-By: Claude Opus 4.8 (1M context) --- runtime/src/gpu_gl_renderer.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/src/gpu_gl_renderer.c b/runtime/src/gpu_gl_renderer.c index 5350264f..7e7dea5a 100644 --- a/runtime/src/gpu_gl_renderer.c +++ b/runtime/src/gpu_gl_renderer.c @@ -347,8 +347,10 @@ static void gpu_triangle(int x0,int y0,uint16_t c0, int x1,int y1,uint16_t c1, int x2,int y2,uint16_t c2, int semi) { ensure_gpu(); float verts[3*6]; - int xs[3] = {x0+s_off_x, x1+s_off_x, x2+s_off_x}; - int ys[3] = {y0+s_off_y, y1+s_off_y, y2+s_off_y}; + /* gpu.c already applied the draw offset before calling the gr_* facade + * (see gp0_exec_* in gpu.c); coords arrive in final VRAM space. */ + int xs[3] = {x0, x1, x2}; + int ys[3] = {y0, y1, y2}; uint16_t cs[3] = {c0,c1,c2}; for (int i = 0; i < 3; i++) { verts[i*6+0] = (float)xs[i]; @@ -389,8 +391,9 @@ static void gpu_textured_triangle(const int *xs, const int *ys, ensure_gpu(); float verts[3 * 8]; for (int i = 0; i < 3; i++) { - verts[i*8+0] = (float)(xs[i] + s_off_x); - verts[i*8+1] = (float)(ys[i] + s_off_y); + /* coords already offset by gpu.c — do not re-apply s_off here */ + verts[i*8+0] = (float)xs[i]; + verts[i*8+1] = (float)ys[i]; verts[i*8+2] = (float)us[i]; verts[i*8+3] = (float)vs[i]; verts[i*8+4] = col[i*3+0];