From 756dd2943a4082e9037c99f0cc0567f9d6cdc59d Mon Sep 17 00:00:00 2001 From: makefunstuff Date: Sun, 30 Jun 2024 20:31:40 +0300 Subject: broken sdl sdl-window --- src/main.zig | 5 +++++ src/sdl-window.zig | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/sdl-window.zig (limited to 'src') 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); + } +} -- cgit 1.4.1-2-gfad0