diff options
author | makefunstuff <[email protected]> | 2024-06-30 19:31:40 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-06-30 19:31:40 +0200 |
commit | 756dd2943a4082e9037c99f0cc0567f9d6cdc59d (patch) | |
tree | 7054ffd9810642c32a6397070be2cea5ad7ea3e6 | |
parent | 38ac26d900f63251529c318106b798769d96e137 (diff) | |
download | tinkerbunk-756dd2943a4082e9037c99f0cc0567f9d6cdc59d.tar.gz |
broken sdl sdl-window
Diffstat (limited to '')
-rw-r--r-- | build.zig | 4 | ||||
-rw-r--r-- | src/main.zig | 5 | ||||
-rw-r--r-- | src/sdl-window.zig | 27 |
3 files changed, 36 insertions, 0 deletions
diff --git a/build.zig b/build.zig index 82f6ce3..9a66a59 100644 --- a/build.zig +++ b/build.zig @@ -22,6 +22,10 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + // linking for linux only + // TODO: link for mac later + exe.linkSystemLibrary("SDL2"); + exe.linkLibC(); // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default // step when running `zig build`). 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); + } +} |