From 30d841f7c633b81669196c5d935a3a28670407a4 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 17 Sep 2020 23:26:25 +0200 Subject: [PATCH] add missing sdl.zig --- in_one_weekend/src/sdl.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 in_one_weekend/src/sdl.zig diff --git a/in_one_weekend/src/sdl.zig b/in_one_weekend/src/sdl.zig new file mode 100644 index 0000000..1f80c96 --- /dev/null +++ b/in_one_weekend/src/sdl.zig @@ -0,0 +1,11 @@ +pub const c = @cImport({ @cInclude("SDL.h"); }); +const Color = @import("vec3.zig").Color; + +pub fn setSurfacePixel(surface: *c.SDL_Surface, i: usize, j: usize, color: Color) void { + const bytePerPixel = 4; + const index = i * bytePerPixel + j * @intCast(usize, surface.*.pitch); + const target_pixel = @ptrToInt(surface.*.pixels) + index; + @intToPtr(*u8, target_pixel + 0).* = @floatToInt(u8, color.z * 255.99); + @intToPtr(*u8, target_pixel + 1).* = @floatToInt(u8, color.y * 255.99); + @intToPtr(*u8, target_pixel + 2).* = @floatToInt(u8, color.x * 255.99); +}