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
|
// Window manipulation
// Copyright (C) 2021 Nguyễn Gia Phong
//
// This file is part of gfz.
//
// gfz is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// gfz is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with gfz. If not, see <https://www.gnu.org/licenses/>.
usingnamespace @import("cimport.zig");
const Error = gfz.Error;
const Monitor = @import("Monitor.zig");
const checkError = gfz.checkError;
const getError = gfz.getError;
const gfz = @import("gfz.zig");
const Window = @This();
pimpl: *GLFWwindow,
/// 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);
return if (ptr) |pimpl|
Window{ .pimpl = pimpl }
else
getError();
}
/// Make the context current for the calling thread.
pub fn makeCurrent(self: Window) Error!void {
glfwMakeContextCurrent(self.pimpl);
try checkError();
}
/// Check the close flag.
pub fn shouldClose(self: Window) Error!bool {
const flag = glfwWindowShouldClose(self.pimpl);
try checkError();
return flag == GLFW_TRUE;
}
pub fn swapBuffers(self: Window) Error!void {
glfwSwapBuffers(self.pimpl);
try checkError();
}
|