raytracing/in_one_weekend/src/sdl.zig

12 lines
581 B
Zig

pub const c = @cImport({ @cInclude("SDL2/SDL.h"); });
const Color = @import("color.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);
}