got vertex buffers running
This commit is contained in:
parent
5cf1b46c20
commit
ef1786df22
1 changed files with 22 additions and 1 deletions
23
src/main.zig
23
src/main.zig
|
@ -50,14 +50,35 @@ pub fn main() void {
|
||||||
// callback function returned?
|
// callback function returned?
|
||||||
_ = gl.glfwSetFramebufferSizeCallback(window, &framebuffer_resize_callback);
|
_ = 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)
|
while(gl.glfwWindowShouldClose(window) == 0)
|
||||||
{
|
{
|
||||||
gl.glfwSwapBuffers(window);
|
|
||||||
gl.glfwPollEvents();
|
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 {
|
export fn framebuffer_resize_callback(_: ?*gl.GLFWwindow, width: c_int, height: c_int) callconv(.C) void {
|
||||||
gl.glViewport(0, 0, width, height);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue