Edit

kc3-lang/kubz/info.c

Branch :

  • info.c
  • /* kc3
     * Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
     *
     * Permission is hereby granted to use this software granted the above
     * copyright notice and this permission paragraph are included in all
     * copies and substantial portions of this software.
     *
     * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
     * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
     * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
     * THIS SOFTWARE.
     */
    #include <libkc3/assert.h>
    #include "../../window.h"
    #include "../gl_font.h"
    #include "../gl_lines.h"
    #include "../mat4.h"
    #include "../gl_ortho.h"
    #include "../gl_square.h"
    #include "../gl_text.h"
    #include "../gl_sprite.h"
    #include "../window_sdl2.h"
    #include "info.h"
    #include "kubz.h"
    
    bool g_info_show = false;
    
    static const s_rgb info_text_color[2] = {
      {1.0f, 1.0f, 1.0f},
      {0.0f, 0.0f, 0.0f}
    };
    
    bool info_render (s_window_sdl2 *window, s_sequence *seq)
    {
      (void) window;
      info_render_fps(seq);
      return true;
    }
    
    void info_render_fps (s_sequence *seq)
    {
      s_window_sdl2 *window;
      char text[80];
      assert(seq);
      window = seq->window;
      assert(window);
      snprintf(text, sizeof(text), "%.1f", (f64) seq->frame / seq->t);
      gl_text_update_1(&g_text_fps, text);
      gl_ortho_text_render_outline(&g_ortho, &g_text_fps,
                                   20, window->h - 40,
                                   info_text_color, info_text_color + 1);
    }