diff --git a/MshViewer/Header/Object.h b/MshViewer/Header/Object.h index f1a17f79e0ec9b8e22c81cf81825ee727a7a04e6..a81c3e1e28a358f08de159b3020c480d71fa99df 100644 --- a/MshViewer/Header/Object.h +++ b/MshViewer/Header/Object.h @@ -71,5 +71,6 @@ private: public: std::vector<GLfloat> getVertex() const; std::vector<GLfloat> getUV() const; + std::list<std::string> getTexture() const; }; diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index 1840247426f1c84756eddcd3832eca93042518ea..296d4169fea595bd64bf933845ca5cfbf6f54c39 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -148,9 +148,10 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c if (!strcmp("PRNT", (*it)->name)) { fsMesh.seekg((*it)->position); - char tempName[33] = { 0 }; - fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size); - dataDestination->parent = tempName; + char* buffer = new char[(*it)->size]; + fsMesh.read(buffer, (*it)->size); + dataDestination->parent = buffer; + delete buffer; continue; } @@ -160,6 +161,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c char* buffer = new char[(*it)->size]; fsMesh.read(buffer, (*it)->size); dataDestination->name = buffer; + delete buffer; continue; } @@ -373,6 +375,7 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>& char* buffer = new char[(*it)->size]; fsMesh.read(buffer, (*it)->size); dataDestination->texture = buffer; + delete buffer; continue; } @@ -491,6 +494,16 @@ std::vector<GLfloat> Object::getUV() const return tempData; } +std::list<std::string> Object::getTexture() const +{ + std::list<std::string> tempData; + + for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++) + tempData.push_back((*it)->texture); + + return tempData; +} + ///////////////////////////////////////////////////////////////////////// // public functions diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index 62622dc8117fc4b67fb872a8160351e2d912cbf1..ce141d82d149204be3b5b520cfdcd0f5d970d642 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -296,12 +296,22 @@ void OpenGLController::loadMsh(const char * path) glGenTextures(1, &gluiTextureID); glBindTexture(GL_TEXTURE_2D, gluiTextureID); -// if texture && open ok, then - //TextureTGA tempTex(TEXTURE_NAME); - //glTexImage2D(GL_TEXTURE_2D, 0, tempTex.hasAlpha() ? GL_RGBA : GL_RGB, tempTex.getWidth(), tempTex.getHeight(), 0, tempTex.hasAlpha() ? GL_BGRA : GL_BGR, GL_UNSIGNED_BYTE, tempTex.getData().data()); -// else - GLubyte solidColor[4] = { 255,0,0,255 }; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA ,1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)solidColor); + std::list<std::string> listTextures; + + + try + { + if (listTextures.empty()) + throw std::invalid_argument("no texture names"); + + TextureTGA tempTex(listTextures.front().c_str()); + glTexImage2D(GL_TEXTURE_2D, 0, tempTex.hasAlpha() ? GL_RGBA : GL_RGB, tempTex.getWidth(), tempTex.getHeight(), 0, tempTex.hasAlpha() ? GL_BGRA : GL_BGR, GL_UNSIGNED_BYTE, tempTex.getData().data()); + } + catch (std::invalid_argument e) + { + GLubyte solidColor[4] = { 255,0,0,255 }; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)solidColor); + } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);