1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
}
|