diff options
Diffstat (limited to 'src/Px.zig')
-rw-r--r-- | src/Px.zig | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/Px.zig b/src/Px.zig new file mode 100644 index 0000000..690dae9 --- /dev/null +++ b/src/Px.zig @@ -0,0 +1,61 @@ +const std = @import("std"); +const sdl = @import("sdl2"); +const Allocator = std.mem.Allocator; + +const Self = @This(); +pub const Color = u8; + +allocator: Allocator, +renderer: sdl.Renderer, +width: u32, +height: u32, +buffer: []Color, +texture: sdl.Texture, + +pub fn init(allocator: Allocator, renderer: sdl.Renderer, width: u32, height: u32) !Self { + var self = Self{ + .allocator = allocator, + .renderer = renderer, + .buffer = undefined, + .width = width, + .height = height, + .texture = undefined, + }; + + self.buffer = try allocator.alloc(Color, width * height); + errdefer allocator.free(self.buffer); + + self.texture = try sdl.createTexture( + renderer, + sdl.PixelFormatEnum.rgba8888, + sdl.Texture.Access.streaming, + width, + height, + ); + errdefer self.texture.destroy(); + + return self; +} + +pub fn deinit(self: *Self) void { + self.texture.destroy(); + self.allocator.free(self.buffer); +} + +pub fn flip(self: *Self) void { + _ = self; + return; + //var pixeldata = try self.texture.lock(null); + //_ = pixeldata; + + //var y: usize = 0; + //while (y < self.height) : (y += 1) { + // var x: usize = 0; + // while (x < self.width) : (x += 1) { + // } + //} +} + +pub fn cls(self: *Self, c: Color) void { + @memset(self.buffer, c); +} |