summaryrefslogtreecommitdiff
path: root/src/screen
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-02-12 12:48:11 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2025-02-12 12:48:11 +0100
commit9fd81c0b38b2b843c24fb61bf8cb5b7873deaa72 (patch)
treea2d4d76a4fcc1334d83c5538e684061913be24d3 /src/screen
parentdae5bc02b1c934075e95694953b4330676e21611 (diff)
graphics: add line
Diffstat (limited to 'src/screen')
-rw-r--r--src/screen/drm/buffer/raw.zig2
-rw-r--r--src/screen/drm/buffer/root.zig2
-rw-r--r--src/screen/drm/pixel.zig18
-rw-r--r--src/screen/drm/request/frame-buffer.zig13
-rw-r--r--src/screen/drm/root.zig1
-rw-r--r--src/screen/main.zig47
6 files changed, 40 insertions, 43 deletions
diff --git a/src/screen/drm/buffer/raw.zig b/src/screen/drm/buffer/raw.zig
index c5a04f3..12784de 100644
--- a/src/screen/drm/buffer/raw.zig
+++ b/src/screen/drm/buffer/raw.zig
@@ -40,7 +40,7 @@ pub const Raw = struct {
.id = 0,
.width = fb.width,
.height = fb.height,
- .pixel_format = drm.Pixel.Format.xrgb8888,
+ .pixel_format = .xrgb8888,
.flags = 0,
.handles = [_] u32 { fb.handle, 0, 0, 0 },
.pitches = [_] u32 { fb.stride, 0, 0, 0 },
diff --git a/src/screen/drm/buffer/root.zig b/src/screen/drm/buffer/root.zig
index f14ed66..30734f2 100644
--- a/src/screen/drm/buffer/root.zig
+++ b/src/screen/drm/buffer/root.zig
@@ -35,7 +35,7 @@ pub const Buffer = struct {
.width = self.current.width,
.height = self.current.height,
.buffer = @as(
- [*]volatile graphics.Pixel,
+ [*]volatile graphics.Color,
@ptrCast(@alignCast(self.current.bytes))
)[0..self.current.bytes.len / 4],
};
diff --git a/src/screen/drm/pixel.zig b/src/screen/drm/pixel.zig
index 7c99e52..8b13789 100644
--- a/src/screen/drm/pixel.zig
+++ b/src/screen/drm/pixel.zig
@@ -1,19 +1 @@
-fn pixel_format_code(comptime a: u8, comptime b: u8, comptime c: u8, comptime d: u8) u32 {
- return @as(u32, @intCast(a)) |
- (@as(u32, @intCast(b)) << 8) |
- (@as(u32, @intCast(c)) << 16) |
- (@as(u32, @intCast(d)) << 24);
-}
-
-pub const Pixel = packed struct(u32) {
- blue: u8,
- green: u8,
- red: u8,
- _padding: u8 = 0x0,
-
- pub const Format = enum(u32) {
- xrgb8888 = pixel_format_code('X', 'R', '2', '4'),
- };
-};
-
diff --git a/src/screen/drm/request/frame-buffer.zig b/src/screen/drm/request/frame-buffer.zig
index 8f93862..c9077e8 100644
--- a/src/screen/drm/request/frame-buffer.zig
+++ b/src/screen/drm/request/frame-buffer.zig
@@ -10,11 +10,22 @@ pub const CreateDumb = extern struct {
size: u32,
};
+fn pixel_format_code(comptime a: u8, comptime b: u8, comptime c: u8, comptime d: u8) u32 {
+ return @as(u32, @intCast(a)) |
+ (@as(u32, @intCast(b)) << 8) |
+ (@as(u32, @intCast(c)) << 16) |
+ (@as(u32, @intCast(d)) << 24);
+}
+
+pub const PixelFormat = enum(u32) {
+ xrgb8888 = pixel_format_code('X', 'R', '2', '4'),
+};
+
pub const FrameBufferCmd2 = extern struct {
id: u32,
width: u32,
height: u32,
- pixel_format: drm.Pixel.Format,
+ pixel_format: PixelFormat,
flags: u32,
handles: [4]u32,
pitches: [4]u32,
diff --git a/src/screen/drm/root.zig b/src/screen/drm/root.zig
index 5012743..2417463 100644
--- a/src/screen/drm/root.zig
+++ b/src/screen/drm/root.zig
@@ -6,4 +6,3 @@ pub const Event = @import("event.zig").Event;
pub const Connector = @import("connector/root.zig").Connector;
pub const Crtc = @import("crtc.zig").Crtc;
pub const Buffer = @import("buffer/root.zig").Buffer;
-pub const Pixel = @import("pixel.zig").Pixel;
diff --git a/src/screen/main.zig b/src/screen/main.zig
index 7b73450..2cb8c03 100644
--- a/src/screen/main.zig
+++ b/src/screen/main.zig
@@ -28,39 +28,44 @@ pub fn main() !void {
try crtc.attach(&buffer, &connector, mode);
- const center_x: i64 = @intCast(buffer.current.width / 2 - 100);
- const center_y: i64 = @intCast(buffer.current.height / 2 - 100);
+ const center_x = (buffer.current.width / 2);
+ const center_y = (buffer.current.height / 2);
- var box = graphics.Box {
- .x = @intCast(center_x),
- .y = @intCast(center_y),
- .width = 200,
- .height = 200,
- .color = .{ .red = 0xff, .green = 0x05, .blue = 0x07 },
- .radius = 0,
+ var line = graphics.Line {
+ .start = .{ .x = center_x, .y = center_y },
+ .end = .{ .x = center_x + 110 , .y = center_y + 100 },
+ .color = .{ .red = 0xff, .green = 0, .blue = 0 },
};
var last_duration: f64 = 0;
- var dir: f64 = 1;
var delta: f64 = 0;
- var radius: f64 = 0;
+ var angle: f64 = 0;
while (true) {
const start = try std.time.Instant.now();
const canvas = buffer.canvas();
+
canvas.fill(.{ .red = 0x25, .green = 0x25, .blue = 0x25 });
- box.render(&canvas);
- radius += delta * dir;
- if (radius > 100) {
- std.debug.print("HERE\n", .{});
- radius = 100;
- dir = -1;
- } else if (radius < 0) {
- radius = 0;
- dir = 1;
+ (graphics.Box {
+ .x = center_x - 100,
+ .y = center_y - 100,
+ .width = 200,
+ .height = 200,
+ .radius = 100,
+ .color = .{ .red = 0xff, .green = 0xff, .blue = 0xff },
+ }).render(&canvas);
+
+ line.render(&canvas);
+ const cos = @cos(std.math.degreesToRadians(angle));
+ const sin = @sin(std.math.degreesToRadians(angle));
+ line.end.x = @intCast(@as(i64, @intCast(center_x)) + @as(i64, @intFromFloat(100 * cos)));
+ line.end.y = @intCast(@as(i64, @intCast(center_y)) + @as(i64, @intFromFloat(100 * sin)));
+
+ angle += delta;
+ if (angle > 360) {
+ angle = 0;
}
- box.radius = @intFromFloat(radius);
const end = try std.time.Instant.now();
const duration: f64 = @floatFromInt(end.since(start));