Commit ef02219af737bf219f2cfd44c601f67eff4eefdd

Thomas de Grivel 2023-12-05T19:45:56

fix toasters

diff --git a/libc3/window/sdl2/demo/toasters.c b/libc3/window/sdl2/demo/toasters.c
index 45642fd..d1ea652 100644
--- a/libc3/window/sdl2/demo/toasters.c
+++ b/libc3/window/sdl2/demo/toasters.c
@@ -54,7 +54,8 @@ static void toast_render (s_tag *toast, s_window_sdl2 *window,
       return;
     }
     glPushMatrix();
-    glTranslated(*x, *y, 0.0);
+    glTranslated(*x, *y + g_toast_sprite.h, 0.0);
+    glScalef(1, -1, 1);
     sdl2_sprite_render(&g_toast_sprite, 0);
     glPopMatrix();
   }
@@ -86,7 +87,8 @@ static void toaster_render (s_tag *toaster, s_window_sdl2 *window,
       return;
     }
     glPushMatrix();
-    glTranslated(*x, *y, 0.0);
+    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));
@@ -116,7 +118,9 @@ bool toasters_render (s_sequence *seq, s_window_sdl2 *window,
   (void) context;
   glClearColor(0.7f, 0.95f, 1.0f, 1.0f);
   glClear(GL_COLOR_BUFFER_BIT);
-  glEnable(GL_TEXTURE_2D);
+  glPushMatrix();
+  glTranslated(0, window->h, 0);
+  glScalef(1, -1, 1);
   /* io_inspect(&seq->tag); */
   if (seq->tag.type == TAG_MAP) {
     toasters = &seq->tag.data.map.values[0].data.list;
@@ -124,6 +128,7 @@ bool toasters_render (s_sequence *seq, s_window_sdl2 *window,
     toasters_render_toasts(toasts, window, seq);
     toasters_render_toasters(toasters, window, seq);
   }
+  glPopMatrix();
   return true;
 }
 
diff --git a/libc3/window/sdl2/sdl2_sprite.c b/libc3/window/sdl2/sdl2_sprite.c
index 2431f5b..e16c3c9 100644
--- a/libc3/window/sdl2/sdl2_sprite.c
+++ b/libc3/window/sdl2/sdl2_sprite.c
@@ -293,18 +293,19 @@ void sdl2_sprite_render (const s_sdl2_sprite *sprite,
   assert(frame < sprite->frame_count);
   frame %= sprite->frame_count;
   glColor4f(1, 1, 1, 1);
-  glEnable(GL_TEXTURE_2D);
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+  glDisable(GL_CULL_FACE);
+  glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, sprite->texture[frame]);
   glBegin(GL_QUADS); {
-    glTexCoord2f(0, 0);
-    glVertex2i(0, 0);
     glTexCoord2f(0, 1);
     glVertex2d(0, sprite->h);
-    glTexCoord2f(1, 1);
-    glVertex2d(sprite->w, sprite->h);  
+    glTexCoord2f(0, 0);
+    glVertex2i(0, 0);
     glTexCoord2f(1, 0);
     glVertex2i(sprite->w, 0);
+    glTexCoord2f(1, 1);
+    glVertex2d(sprite->w, sprite->h);  
   } glEnd();
 }