Commit 4a8fea390461f6958d8ce55ff6a196bccc83b535

Thomas de Grivel 2023-12-08T14:45:08

fix textures

diff --git a/img/flaps.256.png b/img/flaps.256.png
new file mode 100644
index 0000000..2950c1c
Binary files /dev/null and b/img/flaps.256.png differ
diff --git a/img/toast.128.png b/img/toast.128.png
new file mode 100644
index 0000000..f474636
Binary files /dev/null and b/img/toast.128.png differ
diff --git a/libc3/window/sdl2/demo/flies.c b/libc3/window/sdl2/demo/flies.c
index f433976..7d9a718 100644
--- a/libc3/window/sdl2/demo/flies.c
+++ b/libc3/window/sdl2/demo/flies.c
@@ -193,7 +193,7 @@ bool flies_render (s_sequence *seq, s_window_sdl2 *window,
     buf_write_1(&buf, "In ");
     buf_inspect_uw(&buf, fly_in);
     buf_write_u8(&buf, 0);
-    sdl2_font_set_size(&g_font_courier_new, board_item_h, 72);
+    sdl2_font_set_size(&g_font_courier_new, board_item_h, window->dpi);
     sdl2_font_render_text(&g_font_courier_new, buf.ptr.ps8);
     buf_init(&buf, false, sizeof(a), a);
     buf_write_1(&buf, "Out ");
@@ -202,7 +202,7 @@ bool flies_render (s_sequence *seq, s_window_sdl2 *window,
     x = board_item_w * (BOARD_SIZE / 2 + 1);
     glPushMatrix(); {
       glTranslated(x, 0.0, 0.0);
-      sdl2_font_set_size(&g_font_courier_new, board_item_h, 72);
+      sdl2_font_set_size(&g_font_courier_new, board_item_h, window->dpi);
       sdl2_font_render_text(&g_font_courier_new, buf.ptr.ps8);
     } glPopMatrix();
     glTranslated(0.0, board_item_h, 0.0);
diff --git a/libc3/window/sdl2/demo/toasters.c b/libc3/window/sdl2/demo/toasters.c
index 8fbc2a0..c911ca9 100644
--- a/libc3/window/sdl2/demo/toasters.c
+++ b/libc3/window/sdl2/demo/toasters.c
@@ -15,10 +15,15 @@
 #include "../sdl2_sprite.h"
 #include "toasters.h"
 
+#define TOASTERS_SCALE_TOAST 0.5
+#define TOASTERS_SCALE_TOASTER 0.4
+#define TOASTERS_SPACING \
+  (g_sprite_toaster.h * TOASTERS_SCALE_TOASTER * 2.0)
+
 static const f64 g_speed_x =  80.0;
 static const f64 g_speed_y = -40.0;
-s_sdl2_sprite   g_toast_sprite = {0};
-s_sdl2_sprite   g_toaster_sprite = {0};
+s_sdl2_sprite   g_sprite_toast = {0};
+s_sdl2_sprite   g_sprite_toaster = {0};
 
 static bool toasters_render_toasters (s_list **toasters,
                                       s_window_sdl2 *window,
@@ -54,9 +59,9 @@ static void toast_render (s_tag *toast, s_window_sdl2 *window,
       return;
     }
     glPushMatrix();
-    glTranslated(*x, *y + g_toast_sprite.h, 0.0);
-    glScalef(1, -1, 1);
-    sdl2_sprite_render(&g_toast_sprite, 0);
+    glTranslated(*x, *y + g_sprite_toast.h, 0.0);
+    glScalef(TOASTERS_SCALE_TOAST, -TOASTERS_SCALE_TOAST, 1);
+    sdl2_sprite_render(&g_sprite_toast, 0);
     glPopMatrix();
   }
 }
@@ -87,11 +92,11 @@ static void toaster_render (s_tag *toaster, s_window_sdl2 *window,
       return;
     }
     glPushMatrix();
-    glTranslated(*x, *y + g_toaster_sprite.h, 0.0);
-    glScalef(1, -1, 1);
-    sdl2_sprite_render(&g_toaster_sprite,
-                       fmod(seq->t * g_toaster_sprite.frame_count,
-                            g_toaster_sprite.frame_count));
+    glTranslated(*x, *y + g_sprite_toaster.h, 0.0);
+    glScalef(TOASTERS_SCALE_TOASTER, -TOASTERS_SCALE_TOASTER, 1);
+    sdl2_sprite_render(&g_sprite_toaster,
+                       fmod(seq->t * g_sprite_toaster.frame_count,
+                            g_sprite_toaster.frame_count));
     glPopMatrix();
   }
 }
@@ -144,13 +149,15 @@ bool toasters_render_toasts (s_list **toasts, s_window_sdl2 *window,
   assert(toasts);
   assert(window);
   assert(seq);
-  y = window->w * g_speed_y / g_speed_x - 210;
+  y = window->w * g_speed_y / g_speed_x -
+    TOASTERS_SPACING * 3.0 / 2.0 +
+    50;
   if (*toasts && (*toasts)->tag.type == TAG_MAP) {
     t = &(*toasts)->tag.data.map.value[0].data.list;
     y =  (*toasts)->tag.data.map.value[1].data.f64;
   }
-  while (y < window->h - 100) {
-    y += 170.0;
+  while (y < window->h - TOASTERS_SPACING / 2) {
+    y += TOASTERS_SPACING;
     *toasts = list_new_map(2, *toasts);
     map = &(*toasts)->tag.data.map;
     tag_init_sym_1(map->key  + 0, "toasts");
@@ -195,13 +202,14 @@ bool toasters_render_toasters (s_list **toasters, s_window_sdl2 *window,
   assert(window);
   assert(seq);
   /* io_inspect_list((const s_list **) toasters); */
-  y = -100.0;
+  y = -TOASTERS_SPACING - 40;
   if (*toasters && (*toasters)->tag.type == TAG_MAP) {
     t = &(*toasters)->tag.data.map.value[0].data.list;
     y =  (*toasters)->tag.data.map.value[1].data.f64;
   }
-  while (y < window->h - window->w * g_speed_y / g_speed_x) {
-    y += 170.0;
+  while (y < window->h - window->w * g_speed_y / g_speed_x +
+         TOASTERS_SPACING) {
+    y += TOASTERS_SPACING;
     *toasters = list_new_map(2, *toasters);
     map = &(*toasters)->tag.data.map;
     tag_init_sym_1(map->key  + 0, "toasters");
diff --git a/libc3/window/sdl2/demo/toasters.h b/libc3/window/sdl2/demo/toasters.h
index ed562ec..162192c 100644
--- a/libc3/window/sdl2/demo/toasters.h
+++ b/libc3/window/sdl2/demo/toasters.h
@@ -15,8 +15,8 @@
 
 #include "../types.h"
 
-extern s_sdl2_sprite g_toast_sprite;
-extern s_sdl2_sprite g_toaster_sprite;
+extern s_sdl2_sprite g_sprite_toast;
+extern s_sdl2_sprite g_sprite_toaster;
 
 bool toasters_load (s_sequence *seq, s_window_sdl2 *window);
 bool toasters_render (s_sequence *seq, s_window_sdl2 *window,
diff --git a/libc3/window/sdl2/demo/window_sdl2_demo.c b/libc3/window/sdl2/demo/window_sdl2_demo.c
index ae65720..7409977 100644
--- a/libc3/window/sdl2/demo/window_sdl2_demo.c
+++ b/libc3/window/sdl2/demo/window_sdl2_demo.c
@@ -137,10 +137,10 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
   window_sdl2_sequence_init(window->sequence + 1, 20.0,
                             "02. Lightspeed",
                             lightspeed_load, lightspeed_render);
-  if (! sdl2_sprite_init(&g_toaster_sprite, "img/flaps.png",
+  if (! sdl2_sprite_init(&g_sprite_toaster, "img/flaps.256.png",
                          4, 1, 4))
     return false;
-  if (! sdl2_sprite_init(&g_toast_sprite, "img/toast.png",
+  if (! sdl2_sprite_init(&g_sprite_toast, "img/toast.128.png",
                          1, 1, 1))
     return false;
   window_sdl2_sequence_init(window->sequence + 2, 60.0,