diff --git a/engine/include/model.hpp b/engine/include/model.hpp index fb08e1a..c8d2b18 100644 --- a/engine/include/model.hpp +++ b/engine/include/model.hpp @@ -40,7 +40,7 @@ class Model { std::vector getPoints(); private: - GLuint _vbo, _ibo; + GLuint _vbo, _ibo, _normals, _textures; std::vector _points; Model(std::string filename, std::vector vbo, std::vector ibo, int id, std::vector points); diff --git a/engine/src/group.cpp b/engine/src/group.cpp index 9c33565..a017c80 100644 --- a/engine/src/group.cpp +++ b/engine/src/group.cpp @@ -1,11 +1,5 @@ #include "group.hpp" -#include -#include // for M_PI -#include // for memcpy -#include -#include - #include "utils.hpp" Group::Group() { diff --git a/engine/src/main.cpp b/engine/src/main.cpp index 3456e49..c77f207 100644 --- a/engine/src/main.cpp +++ b/engine/src/main.cpp @@ -116,8 +116,8 @@ void renderScene(void) { glMaterialfv(GL_FRONT, GL_SPECULAR, white); glMaterialf(GL_FRONT, GL_SHININESS, 128); - glutSolidTeapot(1.0); - // c.group.drawGroup(); + // glutSolidTeapot(1.0); + c.group.drawGroup(); // renderMenu(); diff --git a/engine/src/model.cpp b/engine/src/model.cpp index 8124bcd..129d7a4 100644 --- a/engine/src/model.cpp +++ b/engine/src/model.cpp @@ -17,15 +17,29 @@ extern "C" { unsigned int counter = 0; -std::vector vPointstoFloats(std::vector points) { +std::vector positionsFloats(std::vector points) { std::vector floats; for (const Vertex& point : points) { floats.push_back(point.position.x); floats.push_back(point.position.y); floats.push_back(point.position.z); + } + return floats; +} + +std::vector normalFloats(std::vector points) { + std::vector floats; + for (const Vertex& point : points) { floats.push_back(point.normal.x); floats.push_back(point.normal.y); floats.push_back(point.normal.z); + } + return floats; +} + +std::vector textureFloats(std::vector points) { + std::vector floats; + for (const Vertex& point : points) { floats.push_back(point.texture.x); floats.push_back(point.texture.y); } @@ -86,28 +100,25 @@ Model::Model(std::string filename, std::vector points) { } void Model::setupModel() { - std::vector floats = vPointstoFloats(this->vbo); + std::vector points = positionsFloats(this->vbo); + std::vector normals = normalFloats(this->vbo); + std::vector textures = textureFloats(this->vbo); // Generate and bind vertex buffer glGenBuffers(1, &this->_vbo); glBindBuffer(GL_ARRAY_BUFFER, this->_vbo); - glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float) * floats.size(), - floats.data(), GL_STATIC_DRAW); - - // Specify the layout of the position data - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), - floats.data()); - glEnableVertexAttribArray(0); + glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float) * points.size(), + points.data(), GL_STATIC_DRAW); - // Specify the layout of the vertex normal data - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), - floats.data() + 3); - glEnableVertexAttribArray(1); + glGenBuffers(1, &this->_normals); + glBindBuffer(GL_ARRAY_BUFFER, this->_normals); + glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float) * normals.size(), + normals.data(), GL_STATIC_DRAW); - // Specify the layout of the texture coordinate data - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), - floats.data() + 6); - glEnableVertexAttribArray(2); + glGenBuffers(1, &this->_textures); + glBindBuffer(GL_ARRAY_BUFFER, this->_textures); + glBufferData(GL_ARRAY_BUFFER, 2 * sizeof(float) * textures.size(), + textures.data(), GL_STATIC_DRAW); // Generate and bind index buffer glGenBuffers(1, &this->_ibo); @@ -126,6 +137,9 @@ void Model::drawModel() { glBindBuffer(GL_ARRAY_BUFFER, this->_vbo); glVertexPointer(3, GL_FLOAT, 0, 0); + glBindBuffer(GL_ARRAY_BUFFER, this->_normals); + glNormalPointer(GL_FLOAT,0,0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->_ibo); glDrawElements(GL_TRIANGLES, this->ibo.size(), GL_UNSIGNED_INT, 0); } diff --git a/engine/src/parse.cpp b/engine/src/parse.cpp index 2e13f0e..590f91c 100644 --- a/engine/src/parse.cpp +++ b/engine/src/parse.cpp @@ -1,10 +1,4 @@ #include "parse.hpp" - -#include -#include -#include -#include - #include "read.hpp" Configuration parseConfig(std::string filename) { diff --git a/scenes/advanced/default.xml b/scenes/advanced/default.xml index 9213757..7a88ddc 100644 --- a/scenes/advanced/default.xml +++ b/scenes/advanced/default.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file