Draw triangle

This commit is contained in:
Dendy 2022-07-22 11:48:44 +02:00
parent ccfeb1fe1b
commit 2385167e87
1 changed files with 20 additions and 0 deletions

View File

@ -27,6 +27,19 @@ pub fn main() !void {
const ctx = try sdl.gl.createContext(window); const ctx = try sdl.gl.createContext(window);
defer sdl.gl.deleteContext(ctx); 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; //var renderer = SDL.SDL_CreateRenderer(window, -1, SDL.SDL_RENDERER_PRESENTVSYNC | SDL.SDL_RENDERER_ACCELERATED) orelse return;
//defer _ = SDL.SDL_DestroyRenderer(renderer); //defer _ = SDL.SDL_DestroyRenderer(renderer);
@ -48,6 +61,13 @@ pub fn main() !void {
gl.clear(.{}); 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.gl.swapWindow(window);
//_ = SDL.SDL_SetRenderDrawColor(renderer, 231, 247, 255, 0xFF); //_ = SDL.SDL_SetRenderDrawColor(renderer, 231, 247, 255, 0xFF);