From 435a6806b91a11a1fa349b0a5f317f4f8ede1455 Mon Sep 17 00:00:00 2001 From: Benjamin Kyd Date: Sun, 24 Feb 2019 19:10:34 +0000 Subject: [PATCH] less broken --- CMakeSettings.json | 15 ++++++++++++ include/object.h | 33 -------------------------- src/mesh.cpp | 28 +++++++++++----------- src/mesh.h | 11 +++++++-- src/object.cpp | 58 ---------------------------------------------- src/util/util.cpp | 2 +- src/util/util.h | 2 +- 7 files changed, 39 insertions(+), 110 deletions(-) delete mode 100644 include/object.h delete mode 100644 src/object.cpp diff --git a/CMakeSettings.json b/CMakeSettings.json index 89f9250..25c4250 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -20,6 +20,21 @@ "cmakeCommandArgs": "", "buildCommandArgs": "-v", "ctestCommandArgs": "" + }, + { + "name": "x64-Build", + "generator": "Ninja", + "configurationType": "Release", + "inheritEnvironments": [ + "msvc_x64_x64" + ], + "buildRoot": "E:\\Projects\\SMH-Engine\\build", + // "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}", + "installRoot": "E:\\Projects\\SMH-Engine\\build", + // "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v", + "ctestCommandArgs": "" } ] } \ No newline at end of file diff --git a/include/object.h b/include/object.h deleted file mode 100644 index 8ddc618..0000000 --- a/include/object.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef SRC_OBJECT_H_ -#define SRC_OBJECT_H_ - -// General includes -#include - -// GL includes -#include - -#if _WIN32 -#include -#else -#include -#endif - -#include -#include -#include - -// Custom includes -#include - -void LoadOBJ(Logger& logger, - std::string file, - std::vector& vertices, - std::vector& normals, - std::vector& elements); - -void FlatShade(std::vector& vertices, - std::vector& normals, - std::vector& elements); - -#endif diff --git a/src/mesh.cpp b/src/mesh.cpp index 1cd270a..c0b16d0 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -6,19 +6,17 @@ Mesh::Mesh() { Mesh::Mesh(std::string objPath) { Logger logger; - //objl::Loader loader; - //bool canLoad = loader.LoadFile(objPath); + objl::Loader loader; + bool canLoad = loader.LoadFile(objPath); - //if (!canLoad) { - // logger << LOGGER_ERROR << "Cannot load obj '" << objPath << "'" << LOGGER_ENDL; - // return; - //} - - LoadOBJ(logger, objPath, vertices, normals, indices); + if (!canLoad) { + logger << LOGGER_ERROR << "Cannot load obj '" << objPath << "'" << LOGGER_ENDL; + return; + } logger << LOGGER_INFO << "Loaded: " << objPath << LOGGER_ENDL; - //loadFromObj(loader.LoadedMeshes[0]); + loadFromObj(loader.LoadedMeshes[0]); } Mesh::Mesh(objl::Mesh objMesh) { @@ -27,7 +25,7 @@ Mesh::Mesh(objl::Mesh objMesh) { void Mesh::loadFromObj(objl::Mesh objMesh) { OBJLtoGLM(objMesh.Vertices, vertices, normals, texCoords); - UintToGLuint(objMesh.Indices, indices); + indices = objMesh.Indices; name = objMesh.MeshName; //Logger logger; @@ -50,13 +48,13 @@ void Mesh::setup() { std::vector toGpu; toGpu.insert(toGpu.end(), vertices.begin(), vertices.end()); toGpu.insert(toGpu.end(), normals.begin(), normals.end()); - //toGpu.insert(toGpu.end(), texCoords.begin(), texCoords.end()); + toGpu.insert(toGpu.end(), texCoords.begin(), texCoords.end()); glBufferData(GL_ARRAY_BUFFER, toGpu.size() * sizeof(glm::vec3), &toGpu[0], GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLushort), + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices[0], GL_STATIC_DRAW); // Positions @@ -70,9 +68,9 @@ void Mesh::setup() { (const void*)(vertices.size() * sizeof(glm::vec3))); // TexCoords - //glEnableVertexAttribArray(2); - //glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, - // (const void*)((vertices.size() + texCoords.size()) * sizeof(glm::vec3))); + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, + (const void*)((vertices.size() + texCoords.size()) * sizeof(glm::vec3))); logger << LOGGER_INFO << "Mesh " << name << " setup" << LOGGER_ENDL; diff --git a/src/mesh.h b/src/mesh.h index d1de707..97ed9af 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -11,12 +11,19 @@ #include #include -#include +// #include #include #include "shader.h" #include "./util/util.h" +// Not in use yet +struct Vertex { + glm::vec3 vertice; + glm::vec3 normal; + glm::vec2 texCoord; +}; + class Mesh { public: Mesh(); @@ -38,7 +45,7 @@ public: // This is a vec3 so it can all pop into //one buffer :) std::vector texCoords; - std::vector indices; + std::vector indices; private: GLuint vertexBuffer; GLuint indexBuffer; diff --git a/src/object.cpp b/src/object.cpp deleted file mode 100644 index 3058aa6..0000000 --- a/src/object.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include - -#include - -// https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Load_OBJ -void LoadOBJ(Logger& logger, std::string file, std::vector& vertices, std::vector& normals, std::vector& elements) { - std::ifstream in(file, std::ios::in); - if (!in) { - logger << LOGGER_ERROR << "Cannot open " << file << LOGGER_ENDL; - return; - } - - std::string line; - while (getline(in, line)) { - if (line.substr(0,2) == "v ") { - std::istringstream s(line.substr(2)); - glm::vec3 v; s >> v.x; s >> v.y; s >> v.z; - vertices.push_back(v); - } else if (line.substr(0,2) == "f ") { - std::istringstream s(line.substr(2)); - GLushort a,b,c; - s >> a; s >> b; s >> c; - a--; b--; c--; - elements.push_back(a); elements.push_back(b); elements.push_back(c); - } else if (line[0] == '#') { } - else {} - } - - normals.resize(vertices.size(), glm::vec3(0.0, 0.0, 0.0)); - for (int i = 0; i < elements.size(); i += 3) { - GLushort ia = elements[i]; - GLushort ib = elements[i+1]; - GLushort ic = elements[i+2]; - glm::vec3 normal = glm::normalize(glm::cross( - glm::vec3(vertices[ib]) - glm::vec3(vertices[ia]), - glm::vec3(vertices[ic]) - glm::vec3(vertices[ia]))); - normals[ia] = normals[ib] = normals[ic] = normal; - } - - logger << LOGGER_INFO << "Loaded OBJ: " << file << LOGGER_ENDL; -} - -void FlatShade(std::vector& vertices, std::vector& normals, std::vector& elements) { - std::vector shared_vertices; - for (int i = 0; i < elements.size(); i++) { - vertices.push_back(shared_vertices[elements[i]]); - if ((i % 3) == 2) { - GLushort ia = elements[i-2]; - GLushort ib = elements[i-1]; - GLushort ic = elements[i]; - glm::vec3 normal = glm::normalize(glm::cross( - shared_vertices[ic] - shared_vertices[ia], - shared_vertices[ib] - shared_vertices[ia])); - for (int n = 0; n < 3; n++) - normals.push_back(normal); - } - } -} diff --git a/src/util/util.cpp b/src/util/util.cpp index b4ef812..b003f62 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -23,7 +23,7 @@ void OBJLtoGLM(std::vector& inVertArr, } void UintToGLuint(std::vector& inIndices, - std::vector& outIndices) { + std::vector& outIndices) { for (int i = 0; i < inIndices.size(); i++) { outIndices.push_back(inIndices[i]); diff --git a/src/util/util.h b/src/util/util.h index 00c1aba..cf9f3cd 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -12,7 +12,7 @@ void OBJLtoGLM(std::vector& inVertArr, std::vector& outTexCoord); void UintToGLuint(std::vector& inIndices, - std::vector& outIndices); + std::vector& outIndices); void OBJLVec3toGLM(objl::Vector3& inVec, glm::vec3& outVec);