diff --git a/QtMeshViewer/Header/GeometryEngine.h b/QtMeshViewer/Header/GeometryEngine.h index 538818d..ee9580c 100644 --- a/QtMeshViewer/Header/GeometryEngine.h +++ b/QtMeshViewer/Header/GeometryEngine.h @@ -25,8 +25,8 @@ private: QVector m_textures; QVector m_drawList; - void initCubeGeometry(); - void initTexture(); + void loadFile(const char* filePath); + void loadTexture(const char* filePath); public: void drawGeometry(QOpenGLShaderProgram *program); diff --git a/QtMeshViewer/Source/GeometryEngine.cpp b/QtMeshViewer/Source/GeometryEngine.cpp index c525a51..bfd83da 100644 --- a/QtMeshViewer/Source/GeometryEngine.cpp +++ b/QtMeshViewer/Source/GeometryEngine.cpp @@ -15,7 +15,7 @@ GeometryEngine::GeometryEngine() m_indexBuf.create(); // Initializes cube geometry and transfers it to VBOs - initCubeGeometry(); + loadFile("..\\Release\\Msh\\triClothMan.msh"); } GeometryEngine::~GeometryEngine() @@ -33,18 +33,21 @@ GeometryEngine::~GeometryEngine() ///////////////////////////////////////////////////////////////////////// // private functions -void GeometryEngine::initCubeGeometry() +void GeometryEngine::loadFile(const char* filePath) { - QVector* models; - QVector vertexData; - QVector indexData; - try { - MshFile file("..\\Release\\Msh\\triClothMan.msh"); - models = file.getModels(); //TODO normalize - //TODO: handle the textures + + QVector* models; + QVector* textureNames; + QVector vertexData; + QVector indexData; + + // open file and get the information + MshFile file(filePath); + models = file.getModels(); + textureNames = file.getTextureNames(); // collect data unsigned int offsetCount(0); @@ -73,6 +76,8 @@ void GeometryEngine::initCubeGeometry() } } + //TODO: cleanup old stuff + // Transfer vertex data to VBO 0 m_arrayBuf.bind(); m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData)); @@ -81,8 +86,15 @@ void GeometryEngine::initCubeGeometry() m_indexBuf.bind(); m_indexBuf.allocate(indexData.data(), indexData.size() * sizeof(GLuint)); - // load the texture - initTexture(); + // get textures path + std::string path = filePath; + + while (path.back() != '/' && path.back() != '\\') + path.pop_back(); + + // load the textures + for(auto& it : *textureNames) + loadTexture(std::string(path + it).c_str()); } catch (std::invalid_argument e) @@ -94,10 +106,18 @@ void GeometryEngine::initCubeGeometry() } -void GeometryEngine::initTexture() +void GeometryEngine::loadTexture(const char* filePath) { - // Load cube.png image - QOpenGLTexture* new_texture = new QOpenGLTexture(QImage(":images/cube.png").mirrored()); + + QImage img; + if (!img.load(filePath)) + { + img = QImage(1, 1, QImage::Format_RGB32); + img.fill(Qt::red); + } + + // Load image to OglTexture + QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored()); // Set nearest filtering mode for texture minification new_texture->setMinificationFilter(QOpenGLTexture::Nearest); diff --git a/QtMeshViewer/Source/MshFile.cpp b/QtMeshViewer/Source/MshFile.cpp index 121aa7b..10e7353 100644 --- a/QtMeshViewer/Source/MshFile.cpp +++ b/QtMeshViewer/Source/MshFile.cpp @@ -17,7 +17,6 @@ MshFile::MshFile(const char * path) MshFile::~MshFile() { - //TODO: clean up }