diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index c116d524325b52f55a328a4e24a38a80fccd70fb..1840247426f1c84756eddcd3832eca93042518ea 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -34,6 +34,7 @@ Object::Object(const char* path) if (!strcmp("MODL", (*it)->name)) { Modl* tempModl = new Modl; + setModlDefault(tempModl); // get all subchunks std::list<ChunkHeader*> tempChunks; @@ -342,9 +343,9 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>& } - std::cout << "vertices" << std::endl; + std::cout << "triangles: " << dataDestination->meshSize << std::endl; for (int i = 0; i < dataDestination->meshSize; i += 3) - std::cout << dataDestination->mesh[i] << " - " << dataDestination->mesh[i + 1] << " - " << dataDestination->mesh[i + 2] << std::endl; + std::cout << dataDestination->mesh[i] << " <> " << dataDestination->mesh[i + 1] << " <> " << dataDestination->mesh[i + 2] << std::endl; continue; @@ -414,12 +415,18 @@ void Object::readVertex(Modl* dataDestination, std::streampos position) dataDestination->vertex = new float[tempSize * 3]; - for (unsigned int i = 0; i < tempSize; i += 3) + for (unsigned int i = 0; i < tempSize * 3; i += 3) { fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float)); fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 1]), sizeof(float)); fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 2]), sizeof(float)); } + + std::cout << "Vertex number: " << tempSize << std::endl; + for (int i = 0; i < tempSize * 3; i += 3) + std::cout << dataDestination->vertex[i] << " <> " << dataDestination->vertex[i + 1] << " <> " << dataDestination->vertex[i + 2] << std::endl; + + } void Object::readUV(Modl* dataDestination, std::streampos position) @@ -452,11 +459,11 @@ std::vector<GLfloat> Object::getVertex() const for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++) { - for (int i = 0; i < (*it)->meshSize; i += 3) + for (unsigned int i = 0; i < (*it)->meshSize; i++) { - tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i]]); - tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] + 1]); - tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] + 2]); + 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]); } } @@ -470,8 +477,12 @@ std::vector<GLfloat> Object::getUV() const for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++) { if ((*it)->uv == NULL) + { + for (unsigned int i = 0; i < (*it)->meshSize; i++) + tempData.push_back(1.0); continue; - for (int i = 0; i < (*it)->meshSize; i++) + } + for (unsigned int i = 0; i < (*it)->meshSize; i++) { tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i]]); } diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index 6060d7a6eb080b6908f023275e5a4d748459910d..62622dc8117fc4b67fb872a8160351e2d912cbf1 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -285,9 +285,7 @@ void OpenGLController::loadMsh(const char * path) { Object obj(path); vfVertices = obj.getVertex(); - - vfUV = loadUV(); - //vfUV = obj.getUV(); + vfUV = obj.getUV(); } catch (std::invalid_argument e) { @@ -295,13 +293,16 @@ void OpenGLController::loadMsh(const char * path) exit(1); } - //vfVertices = loadData(); - //vfUV = loadUV(); - glGenTextures(1, &gluiTextureID); glBindTexture(GL_TEXTURE_2D, gluiTextureID); - 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()); + +// 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); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -324,4 +325,5 @@ void OpenGLController::loadMsh(const char * path) vfUV.data(), GL_STATIC_DRAW ); + }