diff options
| author | Moritz Ruge <ruge.moritz@gmail.com> | 2026-08-06 17:11:31 +0200 |
|---|---|---|
| committer | Moritz Ruge <ruge.moritz@gmail.com> | 2026-08-06 17:12:41 +0200 |
| commit | 21ca79acaf821d825505c20181dc875a375d7a17 (patch) | |
| tree | bf7143b36628900bc48fc6d1d586c9e074e9937d /main.c | |
| parent | 348b224b287cd11c9233c42d38194267ebb5a8dd (diff) | |
triangle exercise 1
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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 // ------------------------------------------ |
