aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Window.zig31
-rw-r--r--src/gfz.zig2
2 files changed, 28 insertions, 5 deletions
diff --git a/src/Window.zig b/src/Window.zig
index bc3b8bd..748e042 100644
--- a/src/Window.zig
+++ b/src/Window.zig
@@ -26,12 +26,35 @@ const gfz = @import("gfz.zig");
const Window = @This();
pimpl: *GLFWwindow,
+const Options = struct {
+ fullscreen: ?Monitor = null,
+ share: ?Window = null,
+};
+
+/// Set the specified window hint to the desired value.
+fn setHint(hint: c_int, value: anytype) Error!void {
+ switch (@TypeOf(value)) {
+ c_int, comptime_int => glfwWindowHint(hint, value),
+ bool => glfwWindowHint(hint, if (value) GLFW_TRUE else GLFW_FALSE),
+ else => unreachable,
+ }
+ try checkError();
+}
+
/// Create a window and its associated context.
pub fn create(width: c_int, height: c_int, title: []const u8,
- monitor: ?Monitor, share: ?Window) Error!Window {
- const pmonitor = if (monitor) |box| box.pimpl else null;
- const pshare = if (share) |box| box.pimpl else null;
- const ptr = glfwCreateWindow(width, height, title.ptr, pmonitor, pshare);
+ options: Options, hints: anytype) Error!Window {
+ const Hints = @TypeOf(hints);
+ // TODO: Add all supported GLFW window hints:
+ // https://www.glfw.org/docs/latest/window_guide.html#window_hints_values
+ if (@hasField(Hints, "depth_bits"))
+ try setHint(GLFW_DEPTH_BITS, hints.depth_bits);
+ if (@hasField(Hints, "double_buffer"))
+ try setHint(GLFW_DOUBLEBUFFER, hints.double_buffer);
+
+ const monitor = if (options.fullscreen) |box| box.pimpl else null;
+ const share = if (options.share) |box| box.pimpl else null;
+ const ptr = glfwCreateWindow(width, height, title.ptr, monitor, share);
return if (ptr) |pimpl|
Window{ .pimpl = pimpl }
else
diff --git a/src/gfz.zig b/src/gfz.zig
index f68461a..53e4aaa 100644
--- a/src/gfz.zig
+++ b/src/gfz.zig
@@ -108,7 +108,7 @@ pub const Window = @import("Window.zig");
test {
try init();
defer deinit() catch unreachable;
- const window = try Window.create(800, 600, "Hello, World!", null, null);
+ const window = try Window.create(800, 600, "Hello, World!", .{}, .{});
try window.makeCurrent();
while (!try window.shouldClose()) {