aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-08-19 14:25:13 +0200
committerdec05eba <dec05eba@protonmail.com>2023-08-19 14:28:46 +0200
commit3d524039fe5562065e6d4ad11411deea1706caa2 (patch)
tree65f69742da793a83bef06c285d7be319713f2515 /src
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/c.zig8
-rw-r--r--src/main.zig48
2 files changed, 56 insertions, 0 deletions
diff --git a/src/c.zig b/src/c.zig
new file mode 100644
index 0000000..4d3f62b
--- /dev/null
+++ b/src/c.zig
@@ -0,0 +1,8 @@
+pub usingnamespace @cImport({
+ @cInclude("mgl/mgl.h");
+ @cInclude("mgl/window/window.h");
+ @cInclude("mgl/window/event.h");
+ @cInclude("mgl/system/fileutils.h");
+ @cInclude("mgl/graphics/font.h");
+ @cInclude("mgl/graphics/text.h");
+}); \ No newline at end of file
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..cc3ae26
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,48 @@
+const std = @import("std");
+const c = @import("c.zig");
+
+pub fn main() !void {
+ if (c.mgl_init() != 0)
+ return error.MglInitFailed;
+ defer c.mgl_deinit();
+
+ var window: c.mgl_window = undefined;
+ var create_params = std.mem.zeroes(c.mgl_window_create_params);
+ create_params.size = .{ .x = 1280, .y = 720 };
+
+ if (c.mgl_window_create(&window, "mgl", &create_params) != 0)
+ return error.MglFailedToCreateWindow;
+ defer c.mgl_window_deinit(&window);
+
+ var font_file: c.mgl_memory_mapped_file = undefined;
+ var file_load_options = c.mgl_memory_mapped_file_load_options{ .readable = true, .writable = false };
+ if (c.mgl_mapped_file_load("/usr/share/fonts/noto/NotoSans-Regular.ttf", &font_file, &file_load_options) != 0)
+ return error.MglFailedToLoadFontFile;
+ defer c.mgl_mapped_file_unload(&font_file);
+
+ var font: c.mgl_font = undefined;
+ if (c.mgl_font_load_from_file(&font, &font_file, 26) != 0)
+ return error.MglFailedToLoadFont;
+ defer c.mgl_font_unload(&font);
+
+ var text: c.mgl_text = undefined;
+ c.mgl_text_init(&text, &font, "hello world", 11);
+ defer c.mgl_text_deinit(&text);
+
+ var event: c.mgl_event = undefined;
+ while (c.mgl_window_is_open(&window)) {
+ while (c.mgl_window_poll_event(&window, &event)) {
+ switch (event.type) {
+ c.MGL_EVENT_TEXT_ENTERED => {
+ const str = event.unnamed_0.text.str[0..@intCast(event.unnamed_0.text.size)];
+ std.debug.print("text event, codepoint: {any}, str: {s}\n", .{ event.unnamed_0.text.codepoint, str });
+ },
+ else => std.debug.print("unhandled event: {any}\n", .{ event.type }),
+ }
+ }
+
+ c.mgl_window_clear(&window, c.mgl_color{ .r = 0, .g = 0, .b = 0, .a = 255});
+ c.mgl_text_draw(c.mgl_get_context(), &text);
+ c.mgl_window_display(&window);
+ }
+} \ No newline at end of file