From ef1786df2218f813680f3b06367edd6dceb4006a Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Mon, 7 Oct 2024 09:37:48 -0700 Subject: [PATCH] got vertex buffers running --- src/main.zig | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index c2ebfb4..351557e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -49,15 +49,36 @@ pub fn main() void { // callback function returned? _ = gl.glfwSetFramebufferSizeCallback(window, &framebuffer_resize_callback); + + const verticies: [3][3]f32 = .{ .{-0.5, -0.5, 0.0}, .{0.5, -0.5, 0.0}, .{0.0, 0.5, 0.0} }; + var vbo: gl.GLuint = undefined; + gl.glad_glGenBuffers.?(1, &vbo); + std.debug.print("buffer id: '{d}'\n", .{ vbo }); + gl.glad_glBindBuffer.?(gl.GL_ARRAY_BUFFER, vbo); + gl.glBufferData(gl.GL_ARRAY_BUFFER, 4 * 3 * @sizeOf(f32), @ptrCast(&verticies), gl.GL_STATIC_DRAW); while(gl.glfwWindowShouldClose(window) == 0) { - gl.glfwSwapBuffers(window); gl.glfwPollEvents(); + handle_input(window.?); + + gl.glClearColor(0.2, 0.3, 0.4, 0.5); // state setting, followed by state using + gl.glClear(gl.GL_COLOR_BUFFER_BIT); // color buffer, depth buffer, and stencil buffer + + // This swaps the "displayed" buffer with the "rendering" buffer + gl.glfwSwapBuffers(window); } + gl.glfwTerminate(); + } export fn framebuffer_resize_callback(_: ?*gl.GLFWwindow, width: c_int, height: c_int) callconv(.C) void { gl.glViewport(0, 0, width, height); } + +fn handle_input(window: *gl.GLFWwindow) void { + if (gl.glfwGetKey(window, gl.GLFW_KEY_ESCAPE) == gl.GLFW_PRESS) { + gl.glfwSetWindowShouldClose(window, 1); + } +}