diff options
| -rw-r--r-- | dc/dc.c | 32 | ||||
| -rw-r--r-- | font.qoi | bin | 1790 -> 1534 bytes | |||
| -rw-r--r-- | teensy/teensy.h | 6 | ||||
| -rw-r--r-- | teensy/teensy_common.h | 4 | ||||
| -rw-r--r-- | teensy/teensy_renderer.c | 45 |
5 files changed, 76 insertions, 11 deletions
@@ -24,11 +24,19 @@ void tick(void) ty_draw_image( img, ty_vec2i( - SCREEN_WIDTH*0.5 + sin(ty_get_time() * 10) * 50 - (img.width*0.5), + SCREEN_WIDTH*0.5 + sin(ty_get_time()) * 50 - (img.width*0.5), SCREEN_HEIGHT*0.5 - (img.height*0.5) ) ); + ty_draw_image_rot( + img, + ty_vec2i(SCREEN_WIDTH/2, SCREEN_HEIGHT/2), + ty_vec2i(-img.width/2, -img.height/2), + TY_PI / 4 + //ty_get_time() + ); + ty_draw_text(&font, ty_vec2i(5, SCREEN_HEIGHT - 5 - 8), "hello, world!"); double frame_time = ty_get_time() - last_frame; @@ -74,6 +82,10 @@ void tick(void) ); y += 8; ty_draw_text(&font, ty_vec2i(5, y), + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + ); + y += 8; + ty_draw_text(&font, ty_vec2i(5, y), "0123456789" ); y += 8; @@ -84,6 +96,15 @@ void tick(void) ty_draw_text(&font, ty_vec2i(5, y), "^_`{}|~:;<>=? " ); + y += 8; + ty_draw_text(&font, ty_vec2i(5, y), + "THe_value = MY_arr[15]" + ); + y += 8; + ty_draw_text_fmt(&font, ty_vec2i(5, y), + "%.2g", + ty_get_time() + ); ty_draw_end(); @@ -128,12 +149,11 @@ int main(void) font_img.data + font_img.width * glyph_height * i ); + uint8_t c = *(uint8_t*)&font_chars[i]; - ty_font_add_glyph( - &font, - *(uint8_t*)&font_chars[i], - glyph - ); + ty_font_add_glyph(&font, c, glyph); + if (c >= 'a' && c <= 'z') + ty_font_add_glyph(&font, c - ('a' - 'A'), glyph); } while (ty_is_game_running()) { Binary files differdiff --git a/teensy/teensy.h b/teensy/teensy.h index 0b7829c..cf0479f 100644 --- a/teensy/teensy.h +++ b/teensy/teensy.h @@ -108,6 +108,12 @@ void ty_draw_image_ex( struct ty_recti src, struct ty_recti dst ); +void ty_draw_image_rot( + struct ty_image img, + struct ty_vec2i pos, + struct ty_vec2i offset, + double rot +); void ty_draw_rect(struct ty_recti rect, struct ty_color color); void ty_draw_line( struct ty_vec2i start, diff --git a/teensy/teensy_common.h b/teensy/teensy_common.h index dc631cb..ea52982 100644 --- a/teensy/teensy_common.h +++ b/teensy/teensy_common.h @@ -9,7 +9,9 @@ #include "teensy_log.h" #include "teensy_mem.h" -#define TY_PI 3.14 +#define TY_PI (3.1415926535897932384626433) +#define TY_TAU (TY_PI * 2) #define TY_DEG2RAD (180 / PI) +#define TY_RAD2DEG (PI / 180) #endif // TEENSY_COMMON_H_ diff --git a/teensy/teensy_renderer.c b/teensy/teensy_renderer.c index d3f73fd..2104695 100644 --- a/teensy/teensy_renderer.c +++ b/teensy/teensy_renderer.c @@ -178,13 +178,50 @@ void ty_draw_image_ex( } } +struct ty_vec2i clamp_point(struct ty_vec2i p, struct ty_recti rect) +{ + p.x = fmin(fmax(p.x, rect.x), rect.w); + p.y = fmin(fmax(p.y, rect.y), rect.h); + return p; +} + +void ty_draw_image_rot( + struct ty_image img, + struct ty_vec2i pos, + struct ty_vec2i offset, + double rot +) { + double s = sin(rot); + double c = cos(rot); + + // x1 = c*x - s*y + // y1 = s*x + c*y + + // FIXME: the corners of the rotated image get cut off. + for (int img_y = 0; img_y < img.height; img_y++) { + for (int img_x = 0; img_x < img.width; img_x++) { + double pixel_x = img_x + offset.x; + double pixel_y = img_y + offset.y; + + int dx = floor(pixel_x * c - pixel_y * s - offset.x); + int dy = floor(pixel_x * s + pixel_y * c - offset.y); + + if (dx < 0 || dx >= img.width || dy < 0 || dy >= img.height) + 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); + } + } +} + void ty_draw_rect(struct ty_recti rect, struct ty_color color) { - int x1 = fmin(fmax(floor(rect.x), 0), r.screen.width); - int y1 = fmin(fmax(floor(rect.y), 0), r.screen.height); + int x1 = fmin(fmax(rect.x, 0), r.screen.width); + int y1 = fmin(fmax(rect.y, 0), r.screen.height); - int x2 = fmin(fmax(floor(rect.x + rect.w), 0), r.screen.width); - int y2 = fmin(fmax(floor(rect.y + rect.h), 0), r.screen.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); for (int dy = y1; dy < y2; dy++) { for (int dx = x1; dx < x2; dx++) { |
