diff --git a/MshViewer/Header/Object.h b/MshViewer/Header/Object.h index b84a6d3..de37568 100644 --- a/MshViewer/Header/Object.h +++ b/MshViewer/Header/Object.h @@ -73,10 +73,6 @@ private: public: - std::vector getVertex() const; - std::vector getUV() const; - std::uint32_t getSize() const; - std::list getTexture() const; std::vector getModels() const; }; diff --git a/MshViewer/Header/OpenGLController.h b/MshViewer/Header/OpenGLController.h index a831426..6c6846b 100644 --- a/MshViewer/Header/OpenGLController.h +++ b/MshViewer/Header/OpenGLController.h @@ -48,9 +48,6 @@ private: // ============================== // data - std::vector vfVertices; - std::vector vfUV; - std::uint32_t ui32MeshSize; std::vector vModels; // transformation =============== diff --git a/MshViewer/Header/import.h b/MshViewer/Header/import.h deleted file mode 100644 index ae99526..0000000 --- a/MshViewer/Header/import.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include -#include - -extern std::vector loadData(); - -extern std::vector loadUV(); diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index 1473f6d..48d7f44 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -61,7 +61,11 @@ Object::Object(const char* path) Object::~Object() { - //delete Chunk list; + // clear texture list + vTextures.clear(); + + // clear Model list (don't delete the elements) + vModls.clear(); } @@ -464,7 +468,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list& fsMesh.seekg((*it)->position); fsMesh.read(reinterpret_cast(&dataDestination->meshSize), sizeof(dataDestination->meshSize)); - dataDestination->mesh = new std::uint32_t[dataDestination->meshSize * 3]; + dataDestination->mesh = new std::uint32_t[dataDestination->meshSize]; for (unsigned int i = 0; i < dataDestination->meshSize; i += 3) { @@ -542,12 +546,8 @@ void Object::readVertex(Modl* dataDestination, std::streampos position) dataDestination->vertex = new float[tempSize * 3]; - for (unsigned int i = 0; i < tempSize * 3; i += 3) - { + for (unsigned int i = 0; i < tempSize * 3; i++) fsMesh.read(reinterpret_cast(&dataDestination->vertex[i]), sizeof(float)); - fsMesh.read(reinterpret_cast(&dataDestination->vertex[i + 1]), sizeof(float)); - fsMesh.read(reinterpret_cast(&dataDestination->vertex[i + 2]), sizeof(float)); - } } void Object::readUV(Modl* dataDestination, std::streampos position) @@ -558,92 +558,14 @@ void Object::readUV(Modl* dataDestination, std::streampos position) dataDestination->uv = new float[tempSize * 2]; - for (unsigned int i = 0; i < tempSize * 2; i += 2) - { + for (unsigned int i = 0; i < tempSize * 2; i++) fsMesh.read(reinterpret_cast(&dataDestination->uv[i]), sizeof(float)); - fsMesh.read(reinterpret_cast(&dataDestination->uv[i + 1]), sizeof(float)); - } } ///////////////////////////////////////////////////////////////////////// // public getter -std::vector Object::getVertex() const -{ - std::vector tempData; - - for (std::vector::const_iterator it = vModls.begin(); it != vModls.end(); it++) - { - if ((*it)->renderFlags == 1) - continue; - - for (unsigned int i = 0; i < (*it)->meshSize; i++) - { - tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3]); - tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 1]); - tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 2]); - } - } - - return tempData; -} - -std::vector Object::getUV() const -{ - std::vector tempData; - - for (std::vector::const_iterator it = vModls.begin(); it != vModls.end(); it++) - { - if ((*it)->renderFlags == 1) - continue; - - if ((*it)->uv == NULL) - { - for (unsigned int i = 0; i < (*it)->meshSize; i++) - tempData.push_back(1.0); - continue; - } - for (unsigned int i = 0; i < (*it)->meshSize; i++) - { - tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i] * 2]); - tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i] * 2 + 1]); - } - } - - return tempData; -} - -std::uint32_t Object::getSize() const -{ - std::uint32_t tempData(0); - - for (std::vector::const_iterator it = vModls.begin(); it != vModls.end(); it++) - { - if ((*it)->renderFlags == 1) - continue; - - tempData += (*it)->meshSize; - } - - return tempData; -} - -std::list Object::getTexture() const -{ - std::list tempData; - - for (std::vector::const_iterator it = vModls.begin(); it != vModls.end(); it++) - { - if ((*it)->renderFlags == 1) - continue; - - tempData.push_back((*it)->texture); - } - - return tempData; -} - std::vector Object::getModels() const { return vModls; diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index d7633f4..eeaea61 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -6,9 +6,10 @@ #include #include "shader.hpp" -#include "import.h" #include "Texture.h" +#include + #define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr" #define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr" //#define TEXTURE_NAME "Textures/texture32R.tga" @@ -31,6 +32,17 @@ OpenGLController::~OpenGLController() glDeleteTextures(1, &gluiSamplerID); glfwTerminate(); + + while (!vModels.empty()) + { + Modl* cursor = vModels.back(); + vModels.pop_back(); + + delete cursor->uv; + delete cursor->mesh; + delete cursor->vertex; + delete cursor; + } } @@ -95,6 +107,27 @@ void OpenGLController::processInit() // draw vertics only from one side glEnable(GL_CULL_FACE); + + // generate stuff + glGenVertexArrays(1, &gluiVertexArrayID); + glBindVertexArray(gluiVertexArrayID); + + glGenBuffers(1, &gluiVertexBufferID); + glGenBuffers(1, &gluiUVBufferID); + + // get the painter ready + try + { + gluiShaderPrgmID = LoadShaders(VERTEX_SHADER, FRAGMENT_SHADER); + } + catch (std::invalid_argument e) + { + MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR); + exit(1); + } + + gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP"); + gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler"); } void OpenGLController::startGLFW() @@ -266,38 +299,11 @@ void OpenGLController::updateScene() void OpenGLController::loadMsh(const char * path) { - // generate stuff - glGenVertexArrays(1, &gluiVertexArrayID); - glBindVertexArray(gluiVertexArrayID); - - glGenBuffers(1, &gluiVertexBufferID); - glGenBuffers(1, &gluiUVBufferID); - - try - { - gluiShaderPrgmID = LoadShaders(VERTEX_SHADER, FRAGMENT_SHADER); - } - catch (std::invalid_argument e) - { - MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR); - exit(1); - } - - gluiMatrixID = glGetUniformLocation(gluiShaderPrgmID, "MVP"); - gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler"); - // get data - std::list listTextures; try { Object obj(path); - vModels = obj.getModels(); - - //vfVertices = obj.getVertex(); - //vfUV = obj.getUV(); - //listTextures = obj.getTexture(); - //ui32MeshSize = obj.getSize(); } catch (std::invalid_argument e) { diff --git a/MshViewer/Source/Texture.cpp b/MshViewer/Source/Texture.cpp index 06f50b4..fae2aeb 100644 --- a/MshViewer/Source/Texture.cpp +++ b/MshViewer/Source/Texture.cpp @@ -108,6 +108,7 @@ TextureTGA::TextureTGA(const char * filePath) TextureTGA::~TextureTGA() { + vui8Pixels.clear(); } std::vector TextureTGA::getData() const diff --git a/MshViewer/Source/import.cpp b/MshViewer/Source/import.cpp deleted file mode 100644 index 1839636..0000000 --- a/MshViewer/Source/import.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include - -std::vector loadData() -{ - return std::vector( - { - -1.0f, -1.0f, -1.0f, //H5 - -1.0f, -1.0f, 1.0f, //H8 - -1.0f, 1.0f, 1.0f, //H7 - 1.0f, 1.0f, -1.0f, //U2 - -1.0f, -1.0f, -1.0f, //U5 - -1.0f, 1.0f, -1.0f, //U6 - 1.0f, -1.0f, 1.0f, //L4 - -1.0f, -1.0f, -1.0f, //L5 - 1.0f, -1.0f, -1.0f, //L1 - 1.0f, 1.0f, -1.0f, //U2 - 1.0f, -1.0f, -1.0f, //U1 - -1.0f, -1.0f, -1.0f, //U5 - -1.0f, -1.0f, -1.0f, //H5 - -1.0f, 1.0f, 1.0f, //H7 - -1.0f, 1.0f, -1.0f, //H6 - 1.0f, -1.0f, 1.0f, //L4 - -1.0f, -1.0f, 1.0f, //L8 - -1.0f, -1.0f, -1.0f, //L5 - -1.0f, 1.0f, 1.0f, //O7 - -1.0f, -1.0f, 1.0f, //O8 - 1.0f, -1.0f, 1.0f, //O4 - 1.0f, 1.0f, 1.0f, //V3 - 1.0f, -1.0f, -1.0f, //V1 - 1.0f, 1.0f, -1.0f, //V2 - 1.0f, -1.0f, -1.0f, //V1 - 1.0f, 1.0f, 1.0f, //V3 - 1.0f, -1.0f, 1.0f, //V4 - 1.0f, 1.0f, 1.0f, //R3 - 1.0f, 1.0f, -1.0f, //R2 - -1.0f, 1.0f, -1.0f, //R6 - 1.0f, 1.0f, 1.0f, //R3 - -1.0f, 1.0f, -1.0f, //R6 - -1.0f, 1.0f, 1.0f, //R7 - 1.0f, 1.0f, 1.0f, //O3 - -1.0f, 1.0f, 1.0f, //O7 - 1.0f, -1.0f, 1.0f //O4 - } - ); -} - -std::vector loadUV() -{ - return std::vector( - { - 0.0f, 0.0f,//587 Links - 1.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 1.0f,//256 Hinten - 1.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 1.0f,//451 Unten - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f,//215 Hinten - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 0.0f,//576 Links - 1.0f, 1.0f, - 0.0f, 1.0f, - 1.0f, 1.0f,//485 Unten - 0.0f, 1.0f, - 0.0f, 0.0f, - 0.0f, 1.0f,//784 Front - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f,//312 Rechts - 1.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f,//134 Rechts - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 0.0f,//326 Oben - 1.0f, 1.0f, - 0.0f, 1.0f, - 1.0f, 0.0f,//367 Oben - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f,//374 Front - 0.0f, 1.0f, - 1.0f, 0.0f - } - ); -} diff --git a/MshViewer/Source/shader.cpp b/MshViewer/Source/shader.cpp index c6812d5..9f71084 100644 --- a/MshViewer/Source/shader.cpp +++ b/MshViewer/Source/shader.cpp @@ -11,7 +11,7 @@ using namespace std; #include "shader.hpp" -GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){ +GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path){ // Create the shaders GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);