aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-14 21:19:36 -0400
committeriamcheeseman <[email protected]>2026-05-14 21:19:36 -0400
commitcfde830b98e235cd2b5a72dca68160c2c1ff3b68 (patch)
tree881f73cfde766d1b5cd510aa3e54b9ccc2aafff9
parent0baf1793f7ebd778a7b63a956d58767b4e3dfe94 (diff)
fix image clipping on the left and top of screen
Previously, texture coordinates would not be correctly calculated because the clamped draw positions were used to decide texture coordinates, instead of the intended draw position.
-rw-r--r--dc/dc.c12
-rw-r--r--teensy/teensy_renderer.c6
2 files changed, 15 insertions, 3 deletions
diff --git a/dc/dc.c b/dc/dc.c
index a654fbe..a532f0a 100644
--- a/dc/dc.c
+++ b/dc/dc.c
@@ -33,6 +33,18 @@ void tick(void)
)
);
+ ty_draw_image_ex(
+ img,
+ ty_recti(
+ 0, 0,
+ img.width, img.height
+ ),
+ ty_recti(
+ sin(-ty_get_time()) * 50, SCREEN_HEIGHT / 2,
+ 32, 64
+ )
+ );
+
ty_draw_image_rot(
img,
ty_vec2i(SCREEN_WIDTH/2, SCREEN_HEIGHT/2),
diff --git a/teensy/teensy_renderer.c b/teensy/teensy_renderer.c
index db9193f..1df1f1b 100644
--- a/teensy/teensy_renderer.c
+++ b/teensy/teensy_renderer.c
@@ -158,7 +158,7 @@ void ty_draw_image(ty_Image img, ty_Vec2i pos)
for (int dx = p1.x; dx < p2.x; dx++) {
ty_Color px = ty_img_get_pixel(
img,
- ty_vec2i(dx - p1.x, dy - p1.y)
+ ty_vec2i(dx - pos.x, dy - pos.y)
);
if (memcmp(&px, &BLEND_COLOR, sizeof(px)) == 0)
continue;
@@ -181,8 +181,8 @@ void ty_draw_image_ex(
for (int dy = p1.y; dy < p2.y; dy++) {
for (int dx = p1.x; dx < p2.x; dx++) {
- int img_x = ((dx - p1.x) * src.w) / dst.w + src.x;
- int img_y = ((dy - p1.y) * src.h) / dst.h + src.y;
+ int img_x = ((dx - dst.x) * src.w) / dst.w + src.x;
+ int img_y = ((dy - dst.y) * src.h) / dst.h + src.y;
ty_Color px = ty_img_get_pixel(img, ty_vec2i(img_x, img_y));
if (memcmp(&px, &BLEND_COLOR, sizeof(px)) == 0)
continue;