Commit eaa4882f4c0d5d30ceb14f4ad22e6fb5251baaa3

Thomas de Grivel 2023-12-08T19:00:50

wip font

diff --git a/libc3/window/sdl2/demo/flies.c b/libc3/window/sdl2/demo/flies.c
index 7d9a718..65c2d47 100644
--- a/libc3/window/sdl2/demo/flies.c
+++ b/libc3/window/sdl2/demo/flies.c
@@ -31,8 +31,9 @@ static const u8  g_board_item_space    = BOARD_ITEM_SPACE;
 static const u8  g_board_item_block    = BOARD_ITEM_BLOCK;
 static const u8  g_board_item_fly      = BOARD_ITEM_FLY;
 static const u8  g_board_item_dead_fly = BOARD_ITEM_DEAD_FLY;
-s_sdl2_sprite    g_dead_fly_sprite     = {0};
-s_sdl2_sprite    g_fly_sprite          = {0};
+s_sdl2_font      g_font_flies          = {0};
+s_sdl2_sprite    g_sprite_dead_fly     = {0};
+s_sdl2_sprite    g_sprite_fly          = {0};
 static const f64 g_xy_ratio            = 0.666;
 
 static void fly_init (s_map *map)
@@ -184,8 +185,10 @@ bool flies_render (s_sequence *seq, s_window_sdl2 *window,
   board_w = board_item_w * BOARD_SIZE;
   board_h = board_item_h * BOARD_SIZE;
   board_x = (window->w - board_w) / 2.0;
-  fly_scale = 2.0 * board_item_w / g_fly_sprite.w;
-  dead_fly_scale = 2.0 * board_item_w / g_dead_fly_sprite.w;
+  fly_scale = 2.0 * board_item_w / g_sprite_fly.w;
+  dead_fly_scale = 2.0 * board_item_w / g_sprite_dead_fly.w;
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+                  GL_LINEAR_MIPMAP_LINEAR);
   glPushMatrix(); {
     glTranslated(board_x, 60.0, 0.0);
     glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
@@ -193,8 +196,9 @@ 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, window->dpi);
-    sdl2_font_render_text(&g_font_courier_new, buf.ptr.ps8);
+    sdl2_font_set_size(&g_font_flies, board_item_h,
+                       window->dpi);
+    sdl2_font_render_text(&g_font_flies, buf.ptr.ps8);
     buf_init(&buf, false, sizeof(a), a);
     buf_write_1(&buf, "Out ");
     buf_inspect_uw(&buf, fly_out);
@@ -202,8 +206,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, window->dpi);
-      sdl2_font_render_text(&g_font_courier_new, buf.ptr.ps8);
+      sdl2_font_render_text(&g_font_flies, buf.ptr.ps8);
     } glPopMatrix();
     glTranslated(0.0, board_item_h, 0.0);
     glColor4f(0.6f, 0.7f, 0.9f, 1.0f);
@@ -230,7 +233,7 @@ bool flies_render (s_sequence *seq, s_window_sdl2 *window,
             glPushMatrix(); {
               glTranslated(-board_item_w / 2.0, -board_item_h / 2.0, 0.0);
               glScaled(fly_scale, fly_scale, 1.0);
-              sdl2_sprite_render(&g_fly_sprite, 0);
+              sdl2_sprite_render(&g_sprite_fly, 0);
             } glPopMatrix();
             if (address[0] == BOARD_SIZE / 2 &&
                 address[1] == BOARD_SIZE - 1) {
@@ -303,7 +306,7 @@ bool flies_render (s_sequence *seq, s_window_sdl2 *window,
               glTranslated(-board_item_w / 2.0, -board_item_h / 2.0,
                            0.0);
               glScaled(dead_fly_scale, dead_fly_scale, 1.0);
-              sdl2_sprite_render(&g_dead_fly_sprite, 0);
+              sdl2_sprite_render(&g_sprite_dead_fly, 0);
             } glPopMatrix();
             break;
           }
diff --git a/libc3/window/sdl2/demo/flies.h b/libc3/window/sdl2/demo/flies.h
index 0f4fb4b..c8feb15 100644
--- a/libc3/window/sdl2/demo/flies.h
+++ b/libc3/window/sdl2/demo/flies.h
@@ -16,8 +16,9 @@
 #include "../types.h"
 #include "window_sdl2_demo.h"
 
-extern s_sdl2_sprite g_dead_fly_sprite;
-extern s_sdl2_sprite g_fly_sprite;
+extern s_sdl2_font   g_font_flies;
+extern s_sdl2_sprite g_sprite_dead_fly;
+extern s_sdl2_sprite g_sprite_fly;
 
 bool flies_load (s_sequence *seq, s_window_sdl2 *window);
 bool flies_render (s_sequence *seq, s_window_sdl2 *window,
diff --git a/libc3/window/sdl2/demo/toasters.c b/libc3/window/sdl2/demo/toasters.c
index c911ca9..ddd297d 100644
--- a/libc3/window/sdl2/demo/toasters.c
+++ b/libc3/window/sdl2/demo/toasters.c
@@ -130,6 +130,8 @@ bool toasters_render (s_sequence *seq, s_window_sdl2 *window,
   if (seq->tag.type == TAG_MAP) {
     toasters = &seq->tag.data.map.value[0].data.list;
     toasts   = &seq->tag.data.map.value[1].data.list;
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+                    GL_LINEAR_MIPMAP_LINEAR);
     toasters_render_toasts(toasts, window, seq);
     toasters_render_toasters(toasters, window, seq);
   }
diff --git a/libc3/window/sdl2/demo/window_sdl2_demo.c b/libc3/window/sdl2/demo/window_sdl2_demo.c
index 7409977..1f05af1 100644
--- a/libc3/window/sdl2/demo/window_sdl2_demo.c
+++ b/libc3/window/sdl2/demo/window_sdl2_demo.c
@@ -146,10 +146,13 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
   window_sdl2_sequence_init(window->sequence + 2, 60.0,
                             "03. Toasters",
                             toasters_load, toasters_render);
-  if (! sdl2_sprite_init(&g_fly_sprite, "img/fly-noto.png",
+  if (! sdl2_font_init(&g_font_flies,
+                       "fonts/Courier New/Courier New.ttf"))
+    return false;
+  if (! sdl2_sprite_init(&g_sprite_fly, "img/fly-noto.png",
                          1, 1, 1))
     return false;
-  if (! sdl2_sprite_init(&g_dead_fly_sprite, "img/fly-dead.png",
+  if (! sdl2_sprite_init(&g_sprite_dead_fly, "img/fly-dead.png",
                          1, 1, 1))
     return false;
   window_sdl2_sequence_init(window->sequence + 3, 60.0,
@@ -170,6 +173,8 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
 static void render_text (s_sdl2_font *font, double x, double y,
                          const s8 *p)
 {
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+                  GL_LINEAR);
   glPushMatrix();
   glTranslated(x, y, 0.0);
   glPushMatrix();