From 2385167e872d5f5eaf34d6a61ca4a6fded11956c Mon Sep 17 00:00:00 2001 From: Dendy Date: Fri, 22 Jul 2022 11:48:44 +0200 Subject: [PATCH] Draw triangle --- src/main.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.zig b/src/main.zig index fd8cc79..5ae2fc0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -27,6 +27,19 @@ pub fn main() !void { const ctx = try sdl.gl.createContext(window); defer sdl.gl.deleteContext(ctx); + var vertex_array = gl.VertexArray.gen(); + vertex_array.bind(); + + const vertex_buffer = [_]f32{ + -1.0, -1.0, 0.0, + 1.0, -1.0, 0.0, + 0.0, 1.0, 0.0, + }; + + const buffer = gl.Buffer.gen(); + buffer.bind(.array_buffer); + buffer.data(f32, &vertex_buffer, .static_draw); + //var renderer = SDL.SDL_CreateRenderer(window, -1, SDL.SDL_RENDERER_PRESENTVSYNC | SDL.SDL_RENDERER_ACCELERATED) orelse return; //defer _ = SDL.SDL_DestroyRenderer(renderer); @@ -48,6 +61,13 @@ pub fn main() !void { gl.clear(.{}); + gl.enableVertexAttribArray(0); + buffer.bind(.array_buffer); + + gl.vertexAttribPointer(0, 3, .float, false, 0, 0); + gl.drawArrays(.triangles, 0, 3); + gl.disableVertexAttribArray(0); + sdl.gl.swapWindow(window); //_ = SDL.SDL_SetRenderDrawColor(renderer, 231, 247, 255, 0xFF);