got vertex buffers running

This commit is contained in:
Nickiel12 2024-10-07 09:37:48 -07:00
parent 5cf1b46c20
commit ef1786df22

View file

@ -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);
}
}