about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authormakefunstuff <[email protected]>2024-06-30 19:31:40 +0200
committermakefunstuff <[email protected]>2024-06-30 19:31:40 +0200
commit756dd2943a4082e9037c99f0cc0567f9d6cdc59d (patch)
tree7054ffd9810642c32a6397070be2cea5ad7ea3e6 /src
parent38ac26d900f63251529c318106b798769d96e137 (diff)
downloadtinkerbunk-756dd2943a4082e9037c99f0cc0567f9d6cdc59d.tar.gz
broken sdl sdl-window
Diffstat (limited to 'src')
-rw-r--r--src/main.zig5
-rw-r--r--src/sdl-window.zig27
2 files changed, 32 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index e5e4099..d712153 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,6 +1,7 @@
 const std = @import("std");
 const ls = @import("ls.zig");
 const socket_server = @import("socket-server.zig");
+const sdl_window = @import("sdl-window.zig");
 
 pub fn main() !void {
     var gpa = std.heap.GeneralPurposeAllocator(.{}){};
@@ -23,6 +24,10 @@ pub fn main() !void {
         try socket_server.start_server();
     }
 
+    if (args.len == 2 and std.mem.eql(u8, args[1], "window")) {
+        try sdl_window.present_sdl_window();
+    }
+
     std.debug.print("Unknown command. Use 'help' for usage information.\n", .{});
     print_help();
 }
diff --git a/src/sdl-window.zig b/src/sdl-window.zig
new file mode 100644
index 0000000..9bd088e
--- /dev/null
+++ b/src/sdl-window.zig
@@ -0,0 +1,27 @@
+const c = @cImport({
+    @cInclude("SDL2/SDL.h");
+});
+
+pub fn present_sdl_window() !void {
+    if (c.SDL_Init(c.SDL_INIT_VIDEO) != 0) {
+        c.SDL_Log("Window is not initialized: %s", c.SDL_GetError());
+    }
+    defer c.SDL_Quit();
+
+    const window = c.SDL_CreateWindow("Aken", c.SDL_WINDOWPOS_CENTERED, c.SDL_WINDOWPOS_CENTERED, 800, 600, c.SDL_WINDOW_OPENGL) orelse {
+        c.SDL_Log("Window create error, reason: %s", c.SDL_GetError());
+        return error.SDLWindowInitError;
+    };
+    defer c.SDL_DestroyWindow(window);
+
+    const renderer = c.SDL_CreateRenderer(window, -1, 0) orelse {
+        c.SDL_Log("Renderer create error, reason: %s", c.SDL_GetError());
+        return error.SDLRendererInitError;
+    };
+    defer c.SDL_DestroyRenderer(renderer);
+
+    while (true) {
+        _ = c.SDL_RenderClear(renderer);
+        c.SDL_RenderPresent(renderer);
+    }
+}