From 21ca79acaf821d825505c20181dc875a375d7a17 Mon Sep 17 00:00:00 2001 From: Moritz Ruge Date: Thu, 6 Aug 2026 17:11:31 +0200 Subject: triangle exercise 1 --- main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 0ebccf8..ff31c74 100644 --- a/main.c +++ b/main.c @@ -46,7 +46,11 @@ int main(void) { -0.5f, -0.5f, 0.0f, // bottom left 0.5f, -0.5f, 0.0f, // bottom right -0.5f, 0.5f, 0.0f, // top left - 0.5f, 0.5f, 0.0f // top right + 0.5f, 0.5f, 0.0f, // top right + // second triangle + 0.8f, 0.9f, 0.0f, // exercise 1 top + 0.9f, 0.7f, 0.0f, // exercise 1 right + 0.7f, 0.7f, 0.0f, // exercise 1 left }; unsigned int indices[] = { 0, 1, 2, // first triangle @@ -147,11 +151,16 @@ int main(void) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + // 1. then set the vertex attributes pointer // location of array, size of vertex attribute (vec3), type of data(float), normialition?, stride (space between data in array), offset of where the position data begins in the buffer glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); + // note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glBindVertexArray(0); // uncomment this call to draw in wireframe polygons. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -177,6 +186,7 @@ int main(void) { glUseProgram(shader_program); glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + glDrawArrays(GL_TRIANGLES, 4, 6); // check and call events and swap the buffers // ------------------------------------------ -- cgit v1.2.3