diff options
| author | iamcheeseman <[email protected]> | 2026-05-11 21:24:49 -0400 |
|---|---|---|
| committer | iamcheeseman <[email protected]> | 2026-05-11 21:24:49 -0400 |
| commit | b34220f5df6ab917f191ee4bc0189ba85065199c (patch) | |
| tree | 7f0ef4f86608f08cc390cbee2278ec967f854c2c /teensy/teensy_renderer.c | |
| parent | f4017a52d90567c2df482c5d553076dc706ac59b (diff) | |
allow the user to change the render target
Diffstat (limited to 'teensy/teensy_renderer.c')
| -rw-r--r-- | teensy/teensy_renderer.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/teensy/teensy_renderer.c b/teensy/teensy_renderer.c index da35738..d457ef6 100644 --- a/teensy/teensy_renderer.c +++ b/teensy/teensy_renderer.c @@ -48,6 +48,7 @@ void ty_init_renderer(void) ctx.hints.scr_height, NULL ); + r.target = r.screen; } void ty_deinit_renderer(void) @@ -119,20 +120,29 @@ int ty_font_width(struct ty_font *font, const char *fmt, ...) return width; } +void ty_draw_set_target(const struct ty_image *img) +{ + if (!img) { + r.target = r.screen; + return; + } + memcpy(&r.target, img, sizeof(r.target)); +} + void ty_draw_clear(struct ty_color col) { assert(is_renderer_init()); - for (int i = 0; i < r.screen.width * r.screen.height; i++) { - r.screen.data[i] = col; + for (int i = 0; i < r.target.width * r.target.height; i++) { + r.target.data[i] = col; } } void ty_draw_image(struct ty_image img, struct ty_vec2i pos) { - int x1 = fmin(fmax(pos.x, 0), r.screen.width); - int y1 = fmin(fmax(pos.y, 0), r.screen.height); - int x2 = fmin(fmax(pos.x + img.width, 0), r.screen.width); - int y2 = fmin(fmax(pos.y + img.height, 0), r.screen.height); + int x1 = fmin(fmax(pos.x, 0), r.target.width); + int y1 = fmin(fmax(pos.y, 0), r.target.height); + int x2 = fmin(fmax(pos.x + img.width, 0), r.target.width); + int y2 = fmin(fmax(pos.y + img.height, 0), r.target.height); for (int dy = y1; dy < y2; dy++) { for (int dx = x1; dx < x2; dx++) { @@ -143,7 +153,7 @@ void ty_draw_image(struct ty_image img, struct ty_vec2i pos) if (memcmp(&px, &BLEND_COLOR, sizeof(px)) == 0) continue; ty_img_set_pixel( - r.screen, + r.target, ty_vec2i(dx, dy), px ); @@ -156,10 +166,10 @@ void ty_draw_image_ex( struct ty_recti src, struct ty_recti dst ) { - int x1 = fmin(fmax(dst.x, 0), r.screen.width); - int y1 = fmin(fmax(dst.y, 0), r.screen.height); - int x2 = fmin(fmax(dst.x + dst.w, 0), r.screen.width); - int y2 = fmin(fmax(dst.y + dst.h, 0), r.screen.height); + int x1 = fmin(fmax(dst.x, 0), r.target.width); + int y1 = fmin(fmax(dst.y, 0), r.target.height); + int x2 = fmin(fmax(dst.x + dst.w, 0), r.target.width); + int y2 = fmin(fmax(dst.y + dst.h, 0), r.target.height); for (int dy = y1; dy < y2; dy++) { for (int dx = x1; dx < x2; dx++) { @@ -170,7 +180,7 @@ void ty_draw_image_ex( continue; ty_img_set_pixel( - r.screen, + r.target, ty_vec2i(dx, dy), px ); @@ -210,23 +220,23 @@ void ty_draw_image_rot( continue; struct ty_color px = ty_img_get_pixel(img, ty_vec2i(dx, dy)); - ty_img_set_pixel(r.screen, ty_vec2i(pos.x + img_x, pos.y + img_y), px); + ty_img_set_pixel(r.target, ty_vec2i(pos.x + img_x, pos.y + img_y), px); } } } void ty_draw_rect(struct ty_recti rect, struct ty_color color) { - int x1 = fmin(fmax(rect.x, 0), r.screen.width); - int y1 = fmin(fmax(rect.y, 0), r.screen.height); + int x1 = fmin(fmax(rect.x, 0), r.target.width); + int y1 = fmin(fmax(rect.y, 0), r.target.height); - int x2 = fmin(fmax(rect.x + rect.w, 0), r.screen.width); - int y2 = fmin(fmax(rect.y + rect.h, 0), r.screen.height); + int x2 = fmin(fmax(rect.x + rect.w, 0), r.target.width); + int y2 = fmin(fmax(rect.y + rect.h, 0), r.target.height); for (int dy = y1; dy < y2; dy++) { for (int dx = x1; dx < x2; dx++) { ty_img_set_pixel( - r.screen, + r.target, ty_vec2i(dx, dy), color ); @@ -257,7 +267,7 @@ void ty_draw_line( int y = start.y + dy * (x - start.x) / dx; ty_img_set_pixel( - r.screen, + r.target, ty_vec2i(x, y), color ); @@ -277,7 +287,7 @@ void ty_draw_line( int x = start.x + dx * (y - start.y) / dy; ty_img_set_pixel( - r.screen, + r.target, ty_vec2i(x, y), color ); |
