Commit 7c7322832769836a7cc0c0e4d44511970a9543fa

Thomas de Grivel 2024-01-10T12:30:41

wip matrix

diff --git a/libc3/window/sdl2/demo/lightspeed.c b/libc3/window/sdl2/demo/lightspeed.c
index 6141f3f..d6aa4d3 100644
--- a/libc3/window/sdl2/demo/lightspeed.c
+++ b/libc3/window/sdl2/demo/lightspeed.c
@@ -92,8 +92,8 @@ bool lightspeed_render (s_sequence *seq)
   window = seq->window;
   assert(window);
   gl_matrix_4f_init_identity(&g_ortho.model_matrix);
-  gl_matrix_4f_scale(&g_ortho.model_matrix, window->w / 2.0,
-                     window->h / 2.0, 1);
+  gl_matrix_4f_scale(&g_ortho.model_matrix, (f32) window->w / 2.0f,
+                     (f32) window->h / 2.0f, 1.0f);
   gl_matrix_4f_translate(&g_ortho.model_matrix, 1, 1, 0);
   gl_ortho_update_model_matrix(&g_ortho);
   star_count = window->w * window->h * LIGHTSPEED_STAR_PROBABILITY;
diff --git a/libc3/window/sdl2/demo/window_sdl2_demo.c b/libc3/window/sdl2/demo/window_sdl2_demo.c
index 388086f..7cc1c93 100644
--- a/libc3/window/sdl2/demo/window_sdl2_demo.c
+++ b/libc3/window/sdl2/demo/window_sdl2_demo.c
@@ -202,6 +202,7 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
   return true;
 }
 
+/*
 static void render_text (s_gl_text *text, f64 x, f64 y)
 {
   assert(glGetError() == GL_NO_ERROR);
@@ -248,7 +249,7 @@ static void render_text (s_gl_text *text, f64 x, f64 y)
   gl_text_render(text);
   assert(glGetError() == GL_NO_ERROR);
 }
-
+*/
 bool window_sdl2_demo_render (s_window_sdl2 *window)
 {
   s_sequence *seq;
@@ -273,10 +274,12 @@ bool window_sdl2_demo_render (s_window_sdl2 *window)
   glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
                       GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
   assert(glGetError() == GL_NO_ERROR);
+  /*
   gl_font_set_size(&g_font_courier_new, 20,
                    (f64) window->gl_h / window->h);
   gl_text_update_1(&g_text_seq_title, seq->title);
   render_text(&g_text_seq_title, 20.0f, 30.0f);
+  */
   /* progress bar */
   glDisable(GL_BLEND);
   assert(glGetError() == GL_NO_ERROR);
@@ -310,11 +313,13 @@ bool window_sdl2_demo_render (s_window_sdl2 *window)
     12 + 2);
   */
   /* fps */
+  /*
   char fps[32];
   snprintf(fps, sizeof(fps), "%.1f", (f64) seq->frame / seq->t);
   gl_text_update_1(&g_text_fps, fps);
   glEnable(GL_BLEND);
   render_text(&g_text_fps, 20, window->h - 30);
+  */
   gl_ortho_render_end(&g_ortho);
   return true;
 }
diff --git a/libc3/window/sdl2/gl_matrix_4f.c b/libc3/window/sdl2/gl_matrix_4f.c
index 9232cd9..7236514 100644
--- a/libc3/window/sdl2/gl_matrix_4f.c
+++ b/libc3/window/sdl2/gl_matrix_4f.c
@@ -32,7 +32,7 @@ sw gl_matrix_4f_buf_inspect (s_buf *buf, const s_gl_matrix_4f *matrix)
   while (i < 4) {
     j = 0;
     while (j < 4) {
-      if ((r = buf_inspect_f32(buf, m)) < 0)
+      if ((r = buf_inspect_f32(buf, m + j * 4 + i)) < 0)
         return r;
       result += r;
       if (i < 3 || j < 3) {
@@ -45,7 +45,6 @@ sw gl_matrix_4f_buf_inspect (s_buf *buf, const s_gl_matrix_4f *matrix)
           result += r;
         }
       }
-      m++;
       j++;
     }
     if (i < 3) {
@@ -231,9 +230,9 @@ s_gl_matrix_4f * gl_matrix_4f_scale (s_gl_matrix_4f *m, f32 x, f32 y,
 s_gl_matrix_4f * gl_matrix_4f_translate (s_gl_matrix_4f *m, f32 x,
                                          f32 y, f32 z)
 {
-  m->xt += x;
-  m->yt += y;
-  m->zt += z;
+  m->tx += x;
+  m->ty += y;
+  m->tz += z;
   return m;
 }
 
diff --git a/libc3/window/sdl2/gl_ortho.c b/libc3/window/sdl2/gl_ortho.c
index 1b943ca..1e80bbf 100644
--- a/libc3/window/sdl2/gl_ortho.c
+++ b/libc3/window/sdl2/gl_ortho.c
@@ -149,6 +149,7 @@ void gl_ortho_resize (s_gl_ortho *ortho, f32 x1, f32 x2, f32 y1, f32 y2,
   gl_matrix_4f_init_identity(&ortho->projection_matrix);
   gl_matrix_4f_ortho(&ortho->projection_matrix, x1, x2, y1, y2,
                      clip_z_near, clip_z_far);
+  err_puts("gl_ortho_resize");
   gl_matrix_4f_buf_inspect(&g_c3_env.err, &ortho->projection_matrix);
   buf_flush(&g_c3_env.err);
 }
@@ -160,6 +161,9 @@ void gl_ortho_update_model_matrix (s_gl_ortho *ortho)
   glUniformMatrix4fv(ortho->gl_model_matrix_loc, 1, GL_FALSE,
                      &ortho->model_matrix.xx);
   assert(glGetError() == GL_NO_ERROR);
+  err_puts("gl_ortho_update_model_matrix");
+  gl_matrix_4f_buf_inspect(&g_c3_env.err, &ortho->model_matrix);
+  buf_flush(&g_c3_env.err);
 }
 
 void gl_ortho_update_view_matrix (s_gl_ortho *ortho)
diff --git a/libc3/window/sdl2/gl_point_3f.c b/libc3/window/sdl2/gl_point_3f.c
index 3fec002..1cf88c6 100644
--- a/libc3/window/sdl2/gl_point_3f.c
+++ b/libc3/window/sdl2/gl_point_3f.c
@@ -56,9 +56,9 @@ s_gl_point_3f * gl_point_3f_init_product (s_gl_point_3f *p,
   assert(p);
   assert(m);
   assert(s);
-  p->x = s->x * m->xx + s->y * m->xy + s->z * m->xz + m->xt;
-  p->y = s->x * m->yx + s->y * m->yy + s->z * m->yz + m->yt;
-  p->z = s->x * m->zx + s->y * m->zy + s->z * m->zz + m->zt;
+  p->x = m->xx * s->x + m->yx * s->y + m->zx * s->z + m->tx;
+  p->y = m->yx * s->x + m->yy * s->y + m->zy * s->z + m->ty;
+  p->z = m->zx * s->x + m->yz * s->y + m->zz * s->z + m->tz;
   return p;
 }
 
diff --git a/libc3/window/sdl2/types.h b/libc3/window/sdl2/types.h
index 2b10053..ebb592e 100644
--- a/libc3/window/sdl2/types.h
+++ b/libc3/window/sdl2/types.h
@@ -99,65 +99,69 @@ struct gl_lines {
 
 struct gl_matrix_3d {
   f64 xx;
-  f64 xy;
-  f64 xz;
   f64 yx;
-  f64 yy;
-  f64 yz;
   f64 zx;
+  f64 xy;
+  f64 yy;
   f64 zy;
+  f64 xz;
+  f64 yz;
   f64 zz;
 };
 
+#pragma pack(push, 1)
 struct gl_matrix_3f {
   f32 xx;
-  f32 xy;
-  f32 xz;
   f32 yx;
-  f32 yy;
-  f32 yz;
   f32 zx;
+  f32 xy;
+  f32 yy;
   f32 zy;
+  f32 xz;
+  f32 yz;
   f32 zz;
 };
+#pragma pack(pop)
 
 struct gl_matrix_4d {
   f64 xx;
-  f64 xy;
-  f64 xz;
-  f64 xt;
   f64 yx;
-  f64 yy;
-  f64 yz;
-  f64 yt;
   f64 zx;
-  f64 zy;
-  f64 zz;
-  f64 zt;
   f64 tx;
+  f64 xy;
+  f64 yy;
+  f64 zy;
   f64 ty;
+  f64 xz;
+  f64 yz;
+  f64 zz;
   f64 tz;
+  f64 xt;
+  f64 yt;
+  f64 zt;
   f64 tt;
 };
 
+#pragma pack(push, 1)
 struct gl_matrix_4f {
   f32 xx;
-  f32 xy;
-  f32 xz;
-  f32 xt;
   f32 yx;
-  f32 yy;
-  f32 yz;
-  f32 yt;
   f32 zx;
-  f32 zy;
-  f32 zz;
-  f32 zt;
   f32 tx;
+  f32 xy;
+  f32 yy;
+  f32 zy;
   f32 ty;
+  f32 xz;
+  f32 yz;
+  f32 zz;
   f32 tz;
+  f32 xt;
+  f32 yt;
+  f32 zt;
   f32 tt;
 };
+#pragma pack(pop)
 
 struct gl_object {
   s_array vertex;