Found it! You have to bind the VAO before attaching it to the VBO. I told you it was one line of code.

This commit is contained in:
Zed A. Shaw 2026-09-09 13:06:29 -04:00
parent 753df69b4c
commit 1107c86036
2 changed files with 14 additions and 15 deletions

View file

@ -2,6 +2,7 @@
#include "dbc.hpp"
#include <math.h>
#include "skybox.hpp"
#include <print>
void Scene::update() {
float currentFrame = glfwGetTime();
@ -84,16 +85,10 @@ void Scene::spawn(const std::string& name, components::Position& position, compo
}
void Scene::setup_instancing() {
int index = 0;
float offset = 0.01f;
int z = -20;
int x = -20;
for(auto& t : translations) {
t.x = (float)x / 2.0f + offset;
t.z = (float)z / 2.0f + offset;
z += 4;
x += 4;
for(size_t i = 0; i < INSTANCE_COUNT; i++) {
translations[i].x = (float)i;
translations[i].z = (float)i;
translations[i].y = 0.0f;
}
glGenBuffers(1, &instanceVBO);
@ -101,11 +96,14 @@ void Scene::setup_instancing() {
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * INSTANCE_COUNT, &translations[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glEnableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), (void*)0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribDivisor(3, 1);
for(auto& mesh : things[0].model.meshes) {
glBindVertexArray(mesh.VAO);
glEnableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), (void*)0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribDivisor(3, 1);
}
// this works
shader.use();