Add a GUI to ZBA #7

Merged
paoda merged 24 commits from imgui into main 2023-03-11 03:18:15 +00:00
2 changed files with 5 additions and 3 deletions
Showing only changes of commit 72b702cb21 - Show all commits

View File

@ -33,9 +33,10 @@ pub const State = struct {
pub fn init(allocator: Allocator, title: [12]u8) !@This() {
const history = try allocator.alloc(u32, histogram_len);
const without_null = std.mem.sliceTo(&title, 0);
return .{
.title = try allocator.dupeZ(u8, &title),
.title = try allocator.dupeZ(u8, without_null),
.fps_hist = RingBuffer(u32).init(history),
};
}
@ -87,7 +88,8 @@ pub fn draw(state: *State, tex_id: GLuint, cpu: *Arm7tdmi) void {
const w = @intToFloat(f32, gba_width * win_scale);
const h = @intToFloat(f32, gba_height * win_scale);
_ = zgui.begin(state.title, .{ .flags = .{ .no_resize = true, .always_auto_resize = true } });
const window_title = if (state.title.len != 0) state.title else "[No Title]";
_ = zgui.begin(window_title, .{ .flags = .{ .no_resize = true, .always_auto_resize = true } });
defer zgui.end();
zgui.image(@intToPtr(*anyopaque, tex_id), .{ .w = w, .h = h, .uv0 = .{ 0, 1 }, .uv1 = .{ 1, 0 } });

View File

@ -182,7 +182,7 @@ pub const Gui = struct {
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, @sizeOf(@TypeOf(indices)), &indices, gl.STATIC_DRAW);
// Position
gl.vertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), @intToPtr(?*anyopaque, 0)); // lmao
gl.vertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), null); // lmao
gl.enableVertexAttribArray(0);
// Colour
gl.vertexAttribPointer(1, 3, gl.FLOAT, gl.FALSE, 8 * @sizeOf(f32), @intToPtr(?*anyopaque, (3 * @sizeOf(f32))));