sadf
This commit is contained in:
parent
45f75ea757
commit
561caf560b
14
main.zig
14
main.zig
@ -130,18 +130,19 @@ fn fillBuffer() !void {
|
|||||||
var buf = std.mem.zeroes([2]u8);
|
var buf = std.mem.zeroes([2]u8);
|
||||||
var slice: []u8 = undefined;
|
var slice: []u8 = undefined;
|
||||||
var bytes_written: u3 = 0;
|
var bytes_written: u3 = 0;
|
||||||
|
var buffer_size: u32 = 0;
|
||||||
|
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
w = try getTermDimension();
|
|
||||||
const file = try std.fs.cwd().createFile("buffer.out", .{});
|
|
||||||
defer file.close();
|
|
||||||
|
|
||||||
var buffer = try allocator.alloc(u8, w.ws_row * w.ws_col * 4); //utf-8 can be 4 bytes long
|
w = try getTermDimension();
|
||||||
|
buffer_size = w.ws_row;
|
||||||
|
buffer_size = buffer_size * w.ws_col * 4;
|
||||||
|
var buffer = try allocator.alloc(u8, buffer_size); //utf-8 can be 4 bytes long
|
||||||
defer allocator.free(buffer);
|
defer allocator.free(buffer);
|
||||||
|
|
||||||
var vec = Vec3{
|
var vec = Vec3{
|
||||||
.a = Point{ .x = 20, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } },
|
.a = Point{ .x = 20, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } },
|
||||||
.b = Point{ .x = 50, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } },
|
.b = Point{ .x = 50, .y = 40, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } },
|
||||||
.c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } },
|
.c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } },
|
||||||
};
|
};
|
||||||
var vec2 = Vec3{
|
var vec2 = Vec3{
|
||||||
@ -166,7 +167,7 @@ fn fillBuffer() !void {
|
|||||||
//_ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 12, .z = 0 });
|
//_ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 12, .z = 0 });
|
||||||
|
|
||||||
try out.print("\x1B[2J", .{});
|
try out.print("\x1B[2J", .{});
|
||||||
//sleep(1000000);
|
//sleep(100000);
|
||||||
|
|
||||||
try triangle(buffer, w, vec);
|
try triangle(buffer, w, vec);
|
||||||
bounce(w, &vec.a, 'x');
|
bounce(w, &vec.a, 'x');
|
||||||
@ -233,6 +234,7 @@ fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void {
|
|||||||
if (i < buffer.len) { //-1 ??
|
if (i < buffer.len) { //-1 ??
|
||||||
const slice = buffer[i .. i + 4];
|
const slice = buffer[i .. i + 4];
|
||||||
_ = try std.unicode.utf8Encode(symbol, slice);
|
_ = try std.unicode.utf8Encode(symbol, slice);
|
||||||
|
//TODO: check length, set not used bytes to zero
|
||||||
} else {
|
} else {
|
||||||
//print("Error illegal memory access\n", .{});
|
//print("Error illegal memory access\n", .{});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user