add missing sdl.zig

master
Fabien Freling 2020-09-17 23:26:25 +02:00
parent 73cb93cf2d
commit 30d841f7c6
1 changed files with 11 additions and 0 deletions

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