From 31b58c48b24d65fe95bade001cd5bcf2e82365e6 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Wed, 2 Aug 2023 00:59:46 +0200 Subject: [PATCH] fix: bind VAO before VBO Failing to do this causes issues when trying to render multiple objects --- src/triangle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/triangle.cpp b/src/triangle.cpp index 976e2be..955f50b 100644 --- a/src/triangle.cpp +++ b/src/triangle.cpp @@ -14,7 +14,7 @@ Triangle::Triangle(GLuint shaderProgram) glBindVertexArray(_vao); glBindBuffer(GL_ARRAY_BUFFER, _vbo); - glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices), &_vertices[0], GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(float), &_vertices[0], GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); @@ -46,8 +46,8 @@ void Triangle::render(float time) float timeValue = time; glUniform1f(timeLocation, timeValue); - glBindBuffer(GL_ARRAY_BUFFER, _vbo); glBindVertexArray(_vao); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); glDrawArrays(GL_TRIANGLES, 0, 3); }