-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1.2.zig
64 lines (53 loc) · 1.88 KB
/
1.2.zig
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
58
59
60
61
62
63
64
const std = @import("std");
const glfw = @import("mach-glfw");
const gl = @import("zgl");
const log = std.log.scoped(.Engine);
const SCR_WIDTH = 800;
const SCR_HEIGHT = 600;
fn glGetProcAddress(p: glfw.GLProc, proc: [:0]const u8) ?gl.binding.FunctionPointer {
_ = p;
return glfw.getProcAddress(proc);
}
/// Default GLFW error handling callback
fn errorCallback(error_code: glfw.ErrorCode, description: [:0]const u8) void {
std.log.err("glfw: {}: {s}\n", .{ error_code, description });
}
pub fn main() !void {
// glfw.setErrorCallback(errorCallback);
if (!glfw.init(.{})) {
std.log.err("failed to initialize GLFW: {?s}", .{glfw.getErrorString()});
std.process.exit(1);
}
defer glfw.terminate();
// Create our window
const window = glfw.Window.create(640, 480, "Learn opengl", null, null, .{
.opengl_profile = .opengl_core_profile,
.context_version_major = 4,
.context_version_minor = 4,
}) orelse {
std.log.err("failed to create GLFW window: {?s}", .{glfw.getErrorString()});
std.process.exit(1);
};
defer window.destroy();
glfw.makeContextCurrent(window);
const proc: glfw.GLProc = undefined;
try gl.loadExtensions(proc, glGetProcAddress);
// render loop
// -----------
while (!window.shouldClose()) {
processInput(window);
// render
// ------
gl.clearColor(0.2, 0.3, 0.3, 1.0);
gl.clear(.{.color = true});
window.swapBuffers();
glfw.pollEvents();
}
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
fn processInput(window: glfw.Window) void {
if (window.getKey(glfw.Key.escape) == glfw.Action.press) {
window.setShouldClose(true);
}
}