add missing sdl.zig
This commit is contained in:
parent
73cb93cf2d
commit
30d841f7c6
11
in_one_weekend/src/sdl.zig
Normal file
11
in_one_weekend/src/sdl.zig
Normal file
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in a new issue