diff options
| -rw-r--r-- | fonts/dejavusans_mono.ttf | bin | 340712 -> 0 bytes | |||
| -rw-r--r-- | main.c | 36 | ||||
| -rw-r--r-- | test/graphics.lua | 11 | ||||
| -rw-r--r-- | test/json.lua | 10 | ||||
| -rw-r--r-- | test/main.lua | 29 | ||||
| -rw-r--r-- | test/test.txt | 1 |
6 files changed, 57 insertions, 30 deletions
diff --git a/fonts/dejavusans_mono.ttf b/fonts/dejavusans_mono.ttf Binary files differdeleted file mode 100644 index f578602..0000000 --- a/fonts/dejavusans_mono.ttf +++ /dev/null @@ -12,8 +12,19 @@ #include "stdlib/color.h" #include "stdlib/tilemap.h" +#include "fonts/dejavusans_mono_bold.h" + #define VERSION "x.x" #define DEBUG_LEVEL LOG_DEBUG +#define FONT_IMPORT_SIZE 30 + +typedef struct { + Font font; + int font_size; +} Context; + +// Setting up global context. +Context ctx = {0}; static int lua_getfield_int(lua_State *L, int index, const char *key) { lua_getfield(L, index, key); @@ -45,6 +56,15 @@ static int l_open_window(lua_State *L) { SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT | FLAG_WINDOW_HIGHDPI); InitWindow(width, height, title); TraceLog(LOG_DEBUG, "l_open_window"); + + ctx.font_size = FONT_IMPORT_SIZE; + ctx.font = LoadFontFromMemory(".ttf", dejavusans_mono_bold, dejavusans_mono_bold_len, ctx.font_size, NULL, 0); + SetTextureFilter(ctx.font.texture, TEXTURE_FILTER_TRILINEAR); + + if (!IsFontValid(ctx.font)) { + printf("font not valid\n"); + } + return 0; } @@ -94,6 +114,19 @@ static int l_draw_fps_meter(lua_State *L) { return 0; } +static int l_draw_info(lua_State *L) { + float delta = GetFrameTime(); + int fps = GetFPS(); + double runtime = GetTime(); + int height = GetScreenHeight(); + + DrawTextEx(ctx.font, TextFormat("dt: %f", delta), (Vector2){ 20, height - 80 }, 20, 0, RAYWHITE); + DrawTextEx(ctx.font, TextFormat("run: %f", runtime), (Vector2){ 20, height - 60 }, 20, 0, RAYWHITE); + DrawTextEx(ctx.font, TextFormat("fps: %d", fps), (Vector2){ 20, height - 40 }, 20, 0, RAYWHITE); + + return 0; +} + static void help(const char *argv0) { printf("Usage: %s [options]\n" "\nAvailable options:\n" @@ -150,6 +183,7 @@ int main(int argc, char *argv[]) { if (run_file) { SetTraceLogLevel(debug_level); + lua_State *L = luaL_newstate(); luaL_openlibs(L); @@ -161,6 +195,7 @@ int main(int argc, char *argv[]) { lua_register(L, "end_drawing", l_end_drawing); lua_register(L, "set_fps", l_set_fps); lua_register(L, "draw_fps_meter", l_draw_fps_meter); + lua_register(L, "draw_info", l_draw_info); lua_register(L, "clear_window", l_clear_window); // Loading embeded modules into Lua state. @@ -174,6 +209,7 @@ int main(int argc, char *argv[]) { return 1; } + UnloadFont(ctx.font); // Unload font from GPU memory (VRAM) lua_close(L); } diff --git a/test/graphics.lua b/test/graphics.lua new file mode 100644 index 0000000..2ac5219 --- /dev/null +++ b/test/graphics.lua @@ -0,0 +1,11 @@ +open_window(800, 800, "My Game") +set_fps(60) + +while window_running() do + begin_drawing() + clear_window(color.BLACK) + draw_info() + end_drawing() +end + +close_window() diff --git a/test/json.lua b/test/json.lua new file mode 100644 index 0000000..f656942 --- /dev/null +++ b/test/json.lua @@ -0,0 +1,10 @@ +local file = io.open("test/test.json", "r") +local content = file:read("*a") +file:close() + +local data = json.decode(content) + +print("name: " .. data.name) +for _, n in pairs(data.numbers) do + print(" - number: " .. n) +end diff --git a/test/main.lua b/test/main.lua deleted file mode 100644 index de44e42..0000000 --- a/test/main.lua +++ /dev/null @@ -1,29 +0,0 @@ -function test_json() - local file = io.open("test/test.json", "r") - local content = file:read("*a") - file:close() - - local data = json.decode(content) - - print("name: " .. data.name) - for _, n in pairs(data.numbers) do - print(" - number: " .. n) - end -end - -function test_graphics() - open_window(600, 600, "My Game") - set_fps(60) - - while window_running() do - begin_drawing() - clear_window(color.BLACK) - draw_fps_meter() - end_drawing() - end - - close_window() -end - -test_json() -test_graphics() diff --git a/test/test.txt b/test/test.txt deleted file mode 100644 index 37ed904..0000000 --- a/test/test.txt +++ /dev/null @@ -1 +0,0 @@ -This is the contents of test.txt file. |
