about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--build.zig11
-rw-r--r--src/sdl-window.zig34
2 files changed, 31 insertions, 14 deletions
diff --git a/build.zig b/build.zig
index 9a66a59..94ee88f 100644
--- a/build.zig
+++ b/build.zig
@@ -54,16 +54,6 @@ pub fn build(b: *std.Build) void {
     const run_step = b.step("run", "Run the app");
     run_step.dependOn(&run_cmd.step);
 
-    // Creates a step for unit testing. This only builds the test executable
-    // but does not run it.
-    const lib_unit_tests = b.addTest(.{
-        .root_source_file = b.path("src/root.zig"),
-        .target = target,
-        .optimize = optimize,
-    });
-
-    const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
-
     const exe_unit_tests = b.addTest(.{
         .root_source_file = b.path("src/main.zig"),
         .target = target,
@@ -76,6 +66,5 @@ pub fn build(b: *std.Build) void {
     // the `zig build --help` menu, providing a way for the user to request
     // running the unit tests.
     const test_step = b.step("test", "Run unit tests");
-    test_step.dependOn(&run_lib_unit_tests.step);
     test_step.dependOn(&run_exe_unit_tests.step);
 }
diff --git a/src/sdl-window.zig b/src/sdl-window.zig
index 9bd088e..2e292ed 100644
--- a/src/sdl-window.zig
+++ b/src/sdl-window.zig
@@ -3,12 +3,15 @@ const c = @cImport({
 });
 
 pub fn present_sdl_window() !void {
+    const WINDOW_WIDTH: u32 = 800;
+    const WINDOW_HEIGHT: u32 = 600;
+
     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 {
+    const window = c.SDL_CreateWindow("Aken", c.SDL_WINDOWPOS_CENTERED, c.SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, c.SDL_WINDOW_OPENGL) orelse {
         c.SDL_Log("Window create error, reason: %s", c.SDL_GetError());
         return error.SDLWindowInitError;
     };
@@ -20,8 +23,33 @@ pub fn present_sdl_window() !void {
     };
     defer c.SDL_DestroyRenderer(renderer);
 
-    while (true) {
+    const color = c.SDL_Color{ .r = 255, .g = 255, .b = 255, .a = 255 };
+    _ = c.SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
+
+    const rect_height = 100;
+    const rect_width = 100;
+
+    const rect_x = WINDOW_WIDTH / 2 - rect_width / 2;
+    const rect_y = WINDOW_HEIGHT / 2 - rect_height / 2;
+
+    const rect = c.SDL_Rect{ .x = rect_x, .y = rect_y, .w = rect_width, .h = rect_height };
+
+    var quit = false;
+    while (!quit) {
+        var event: c.SDL_Event = undefined;
+
+        while (c.SDL_PollEvent(&event) != 0) {
+            switch (event.type) {
+                c.SDL_Quit => {
+                    quit = true;
+                },
+                else => {},
+            }
+        }
+        _ = c.SDL_RenderFillRect(renderer, &rect);
         _ = c.SDL_RenderClear(renderer);
-        c.SDL_RenderPresent(renderer);
+        _ = c.SDL_RenderPresent(renderer);
+
+        _ = c.SDL_Delay(20);
     }
 }