about summary refs log tree commit diff
path: root/src/Window.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Window.zig')
-rw-r--r--src/Window.zig31
1 files changed, 27 insertions, 4 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