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); +}