From 511b2da3199c3914d1e6438097e855cedcff97a5 Mon Sep 17 00:00:00 2001 From: karl Date: Tue, 7 Jan 2020 18:12:43 +0100 Subject: [PATCH] A cube is rendered with the new system! --- ECS/Components/Mesh.h | 13 ++++++++----- Shaders/default-vertex.vs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ECS/Components/Mesh.h b/ECS/Components/Mesh.h index e5c0715..8b685d1 100644 --- a/ECS/Components/Mesh.h +++ b/ECS/Components/Mesh.h @@ -10,14 +10,20 @@ #include struct Mesh { - explicit Mesh(std::vector vertices) : vertices(vertices), vertex_count(vertices.size() / 5) { + explicit Mesh(const std::vector &_vertices) : vertex_count(_vertices.size()) { + // Copy the vertices into a local classic float array. Nothing was displayed without this, maybe + // due to weird hidden type incompatibility or out of scope issues? + float vertices[vertex_count]; + std::copy(_vertices.begin(), _vertices.end(), vertices); + glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); + // bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s). glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(&vertices), &vertices, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // position attribute glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); @@ -37,9 +43,6 @@ private: unsigned int VBO; unsigned int VAO; unsigned int vertex_count; - - /// Vertices in the format x, y, z, u, v - std::vector vertices; }; #endif //ECSGAME_MESH_H diff --git a/Shaders/default-vertex.vs b/Shaders/default-vertex.vs index 661a5f9..501637b 100644 --- a/Shaders/default-vertex.vs +++ b/Shaders/default-vertex.vs @@ -1,6 +1,6 @@ #version 320 es layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 uvPos; +layout (location = 1) in vec2 uvPos; uniform mat4 model; uniform mat4 view;